IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

Probleme avec autoComplete


Sujet :

JSF Java

  1. #1
    Membre confirmé
    Inscrit en
    Décembre 2009
    Messages
    68
    Détails du profil
    Informations forums :
    Inscription : Décembre 2009
    Messages : 68
    Par défaut Probleme avec autoComplete
    Salut, j'essaie de commencer avec les autocomplete et feja j'ai quelques problemes. Quand j'entre des lettres dans mon champs rien ne s'affiche. j'ai fait un debug et j'ai trouvé que le managed property du bean était toujours nulle je vous envoie mes fichiers de config ainsi que mon bean.
    EmployeDicBean
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    package com.sungard.bean;
     
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import javax.faces.model.SelectItem;
    import com.sungard.persistence.Employe;
    import com.sungard.service.IEmployeService;
     
    public class EmployeDicBean {
     
    	private IEmployeService empServ;
    	private static ArrayList<SelectItem> employesDic;
    	private ArrayList<Employe> emps;
     
     
     
     
    	public IEmployeService getEmpServ() {
    		return empServ;
    	}
     
    	public void setEmpServ(IEmployeService empServ) {
    		this.empServ = empServ;
    	}
     
     
     
     
     
    	public EmployeDicBean() {
     
    		emps=new ArrayList<Employe>();
    		if(emps==null){
    			emps=new ArrayList<Employe>();
    			emps = empServ.findEmployes();
    		}
    		employesDic=new ArrayList<SelectItem>();
    		Employe e;
    		for(int i=0; i<emps.size(); i++){
    			e=(Employe)emps.get(i);
    			if(e!=null && e.getNom()!=null){
    				employesDic.add(new SelectItem(e,e.getNom()));
    			}
    		}
    		emps.clear();
    		Collections.sort(employesDic, LABEL_COMPARATOR);
     
     
    	}	
        private static final Comparator LABEL_COMPARATOR = new Comparator() {
     
            public int compare(Object o1, Object o2) {
                SelectItem selectItem1 = (SelectItem) o1;
                SelectItem selectItem2 = (SelectItem) o2;
     
                return selectItem1.getLabel().compareToIgnoreCase(selectItem2.getLabel());
            }
        };
     
        public ArrayList generateEmpMatches(String searchWord, int maxMatches) {
     
            ArrayList matchList = new ArrayList(maxMatches);
     
            // ensure the autocomplete search word is present
            if ((searchWord == null) || (searchWord.trim().length() == 0)) {
                return matchList;
            }
     
            try {
                SelectItem searchItem = new SelectItem("", searchWord); 
                int insert = Collections.binarySearch(
                		employesDic,
                        searchItem,
                        LABEL_COMPARATOR);
     
                if (insert < 0) {
                    insert = Math.abs(insert) - 1;
                }
                else {
     
                    if(insert != employesDic.size() && LABEL_COMPARATOR.compare(searchItem, employesDic.get(insert)) == 0) {
                        while(insert > 0 && LABEL_COMPARATOR.compare(searchItem, employesDic.get(insert-1)) == 0) {
                            insert = insert - 1;
                        }
                    }
                }
     
                for (int i = 0; i < maxMatches; i++) {
     
                    if ((insert + i) >= employesDic.size() ||
                            i >= maxMatches) {
                        break;
                    }
                    matchList.add(employesDic.get(insert + i));
                }
            } catch (Throwable e) {
     
            }
     
            return matchList;
        }
     
    	public ArrayList<SelectItem> getEmployesDic() {
     
    		return employesDic;
    	}
     
    	public void setEmployesDic(ArrayList<SelectItem> employesDic) {
    		this.employesDic = employesDic;
    	}
     
    	public ArrayList<Employe> getEmps() {
    		if(emps==null){
    			emps=new ArrayList<Employe>();
    			emps = empServ.findEmployes();
    		}
    		return emps;
    	}
    	public void setEmps(ArrayList<Employe> emps) {
    		this.emps = emps;
    	}
     
     
     
     
    }
    EmployeBean
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    package com.sungard.bean;
     
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
     
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.model.SelectItem;
     
    import com.icesoft.faces.component.selectinputtext.SelectInputText;
    import com.sungard.persistence.Employe;
    import com.sungard.service.EmployeService;
    import com.sungard.service.IEmployeService;
     
    public class EmployeBean extends BaseBean{
     
    	private String nom;
    	private String prenom;
    	private String fonction;
    	private int id;
     
    	private Employe selectedEmp;
    	private IEmployeService empServ;
     
    	private EmployeDicBean employesDic;
    	private List empMatches;
    	private static int employesLength=10;
    	private String selectedEmpValue1 = "";
    	private String selectedEmpValue2 = "";
     
     
     
     
     
    	public EmployeBean() {
     
    		selectedEmp=new Employe();
    	}
     
     
    	 public void selectInputValueChanged(ValueChangeEvent event) {
     
    		 	employesDic=new EmployeDicBean();
    	        if (event.getComponent() instanceof SelectInputText) {
     
     
    	            SelectInputText autoComplete =(SelectInputText) event.getComponent();
     
    	            String newWord = (String) event.getNewValue();
     
    	            empMatches =employesDic.generateEmpMatches(newWord, employesLength);
     
     
    	            if (autoComplete.getSelectedItem() != null) {
    	                selectedEmp = (Employe) autoComplete.getSelectedItem().getValue();
    	                // fire effect to draw attention
    	                valueChangeEffect.setFired(false);
    	            }
     
    	            else{
    	                Employe tmp = getFindEmpMatch(newWord);
    	                if (tmp != null){
    	                    selectedEmp = tmp;
    	                    valueChangeEffect.setFired(false);
    	                }
    	            }
     
    	        }
    	    }
     
     
        private Employe getFindEmpMatch(String empName) {
        	if (empMatches != null) {
                SelectItem employe;
                for(int i = 0, max = empMatches.size(); i < max; i++){
                    employe = (SelectItem)empMatches.get(i);
                    if (employe.getLabel().compareToIgnoreCase(empName) == 0) {
                        return (Employe) employe.getValue();
                    }
                }
            }
            return null;
        }
     
    	public EmployeDicBean getEmployesDic() {
    		return employesDic;
    	}
    	public void setEmployesDic(EmployeDicBean employesDic) {
    		this.employesDic = employesDic;
    	}
    	public List getEmpMatches() {
    		return empMatches;
    	}
    	public void setEmpMatches(List empMatches) {
    		this.empMatches = empMatches;
    	}
    	public static int getEmployesLength() {
    		return employesLength;
    	}
    	public static void setEmployesLength(int employesLength) {
    		EmployeBean.employesLength = employesLength;
    	}
    	public String getSelectedEmpValue1() {
    		return selectedEmpValue1;
    	}
    	public void setSelectedEmpValue1(String selectedEmpValue1) {
    		this.selectedEmpValue1 = selectedEmpValue1;
    	}
    	public String getSelectedEmpValue2() {
    		return selectedEmpValue2;
    	}
    	public void setSelectedEmpValue2(String selectedEmpValue2) {
    		this.selectedEmpValue2 = selectedEmpValue2;
    	}
    	public IEmployeService getEmpServ() {
    		return empServ;
    	}
    	public void setEmpServ(IEmployeService empServ) {
    		this.empServ = empServ;
    	}
     
    	public Employe getSelectedEmp() {
    		return selectedEmp;
    	}
    	public void setSelectedEmp(Employe emp) {
    		this.selectedEmp = emp;
    	}
    	public String getNom() {
    		return nom;
    	}
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
    	public String getPrenom() {
    		return prenom;
    	}
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
    	public String getFonction() {
    		return fonction;
    	}
    	public void setFonction(String fonction) {
    		this.fonction = fonction;
    	}
    	public int getId() {
    		return id;
    	}
    	public void setId(int id) {
    		this.id = id;
    	}
    }
    faces-config.xml
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    <?xml version="1.0" encoding="UTF-8"?>
     
    <!DOCTYPE faces-config PUBLIC
        "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
        "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
     
    <faces-config>
    	<application>
    		<variable-resolver>
    			org.springframework.web.jsf.DelegatingVariableResolver
    		</variable-resolver>
    		<locale-config />
    	</application>
    	<application>
    		<view-handler>
    			com.icesoft.faces.facelets.D2DFaceletViewHandler
    		</view-handler>
    	</application>
    	<managed-bean>
    		<managed-bean-name>employeBean</managed-bean-name>
    		<managed-bean-class>
    			com.sungard.bean.EmployeBean
    		</managed-bean-class>
    		<managed-bean-scope>request</managed-bean-scope>
    		<managed-property>
    			<property-name>employesDic</property-name>
    			<property-class>
    				com.sungard.bean.EmployeDicBean
    			</property-class>
    			<value>#{employesDic}</value>
    		</managed-property>
    		<managed-property>
    			<property-name>empServ</property-name>
    			<property-class>
    				com.sungard.service.IEmployeService
    			</property-class>
    			<value>#{empServ}</value>
    		</managed-property>
    	</managed-bean>
    	<managed-bean>
    		<managed-bean-name>employeDicBean</managed-bean-name>
    		<managed-bean-class>
    			com.sungard.bean.EmployeDicBean
    		</managed-bean-class>
    		<managed-bean-scope>application</managed-bean-scope>
    		<managed-property>
    			<property-name>empServ</property-name>
    			<property-class>
    				com.sungard.service.IEmployeService
    			</property-class>
    			<value>#{empServ}</value>
    		</managed-property>
    	</managed-bean>
    </faces-config>

  2. #2
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Par défaut
    donne nous le code de ta page plutôt, le code qui pose problème.

Discussions similaires

  1. [AJAX] Autocompletion et Array
    Par aritas dans le forum AJAX
    Réponses: 1
    Dernier message: 24/02/2012, 14h45
  2. Réponses: 19
    Dernier message: 08/06/2010, 14h20
  3. [AJAX] Ajax.Autocompleter avec id
    Par darontankian dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 30/10/2008, 17h29
  4. [AjaxTags] Probleme avec ajaxtags autocomplete
    Par abylone dans le forum Taglibs
    Réponses: 0
    Dernier message: 15/09/2008, 17h26
  5. [Kylix] probleme avec un imagelist
    Par NicoLinux dans le forum EDI
    Réponses: 4
    Dernier message: 08/06/2002, 23h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo