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 :

Actualiser les items d'un selectOneMenu sur un onchange d'un autre selectOneMenu


Sujet :

JSF Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Janvier 2010
    Messages
    12
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 12
    Par défaut Actualiser les items d'un selectOneMenu sur un onchange d'un autre selectOneMenu
    Salut,

    Voila j'ai deux selectOneMenus, un pour une liste de catégories, un autre pour une liste de sous-catégories et j'essaie de rafraichir et filtrer ma liste de sous-catégories à la sélection d'une catégorie.

    J'arrive bien a lancer ma méthode refreshSubTypeList() mais ma liste de sous-catégorie n'est pas actualisée.

    JSP:
    Code : 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
     
    <h:form>
    ...
               <s:decorate template="layout/edit.xhtml">
                    <ui:define name="label">Catégorie</ui:define>
                    	<h:selectOneMenu id="productType" rendered="#{not empty typeList.resultList}" value="#{productList.product.productSubType.subTypeType.typeId}">
    						<s:selectItems value="#{typeList.resultList}" var="type" label="#{type.typeName}"  itemValue="#{type.typeId}" noSelectionLabel=""/>
    						<a4j:support event="onchange" reRenderAfterComplete="productSubType" action="#{productList.refreshSubTypeList}"/>
    					</h:selectOneMenu>
                </s:decorate>
     
                <s:decorate template="layout/edit.xhtml">
                    <ui:define name="label">Sous catégorie</ui:define>
                    	<h:selectOneMenu id="productSubType" rendered="#{not empty productList.checkSubTypeList.resultList}" value="#{productList.product.productSubType.subTypeId}">
    						<s:selectItems value="#{productList.subTypeList.resultList}" var="subType" label="#{subType.subTypeName}" itemValue="#{subType.subTypeId}" noSelectionLabel="" />
    			     	</h:selectOneMenu>
                </s:decorate>
    ...
        </h:form>
    Bean:
    Code : 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
     
    @Name("productList")
    @Scope(ScopeType.SESSION)
    public class ProductList extends EntityQuery<Product> {
     
    ...
     
    	@In(create = true)
    	SubTypeList subTypeList;
     
    ...
     
    	public SubTypeList getSubTypeList() {
    		System.out.println("get subType list <<<<<<<<<<<<<<<<<<<<");
    		System.out.println("subType list current count filter: "+subTypeList.getResultCount());
    		System.out.println("end get subType list --");
    		return subTypeList;
    	}
     
    	public SubTypeList getCheckSubTypeList() {
    		System.out.println("check subType list ???????????????????");
    		System.out.println("subType list current count filter: "+subTypeList.getResultCount());
    		System.out.println("end check subType list --");
    		return subTypeList;
    	}
     
    	@SuppressWarnings("unchecked")
    	public void refreshSubTypeList() {
     
    		System.out.println("refresh subType list ******************");
    		System.out.println("-> id Type:"+product.getProductSubType().getSubTypeType().getTypeId());
     
    		if(product.getProductSubType().getSubTypeType().getTypeId()==null){
    			System.out.println("no restrictions");
    			List<ValueExpression> restrictions = subTypeList.getRestrictions();
    			for (ValueExpression valueExpression : restrictions) {
    				System.out.println("vExp: "+valueExpression.getExpressionString() );
    			}
    			subTypeList.setRestrictions(new ArrayList<ValueExpression>());
    		} else {
    			System.out.println("restrictions");
    			List<ValueExpression> restrictions = new ArrayList<ValueExpression>();
    	        restrictions.add(createValueExpression("subType.subTypeType.typeId = #{productList.product.productSubType.subTypeType.typeId}"));
    			subTypeList.setRestrictions(restrictions);
    			System.out.println("updated restrictions");
    		}
    		//subTypeList.refresh();
    		System.out.println("refresh subType list end count filter: "+subTypeList.getResultCount());
     
    	}
    }
    Message console à l'ouverture de la page:
    Code : 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
     
    11:33:51,873 INFO  [STDOUT] Hibernate: 
        select
            type0_.typeId as typeId150_,
            type0_.typeName as typeName150_ 
        from
            evercat.type type0_ limit ?
    11:33:51,881 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,882 INFO  [STDOUT] Hibernate: 
        select
            count(subtype0_.subTypeId) as col_0_0_ 
        from
            evercat.subType subtype0_ limit ?
    11:33:51,883 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,883 INFO  [STDOUT] end check subType list --
    11:33:51,884 INFO  [STDOUT] Hibernate: 
        select
            subtype0_.subTypeId as subTypeId140_,
            subtype0_.subTypeName as subTypeN2_140_,
            subtype0_.typeId as typeId140_ 
        from
            evercat.subType subtype0_ limit ?
    11:33:51,886 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,886 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,886 INFO  [STDOUT] end check subType list --
    11:33:51,887 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,888 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,888 INFO  [STDOUT] end check subType list --
    11:33:51,889 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,889 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,889 INFO  [STDOUT] end check subType list --
    11:33:51,890 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,890 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,890 INFO  [STDOUT] end check subType list --
    11:33:51,891 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,892 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,892 INFO  [STDOUT] end check subType list --
    11:33:51,893 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,893 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,893 INFO  [STDOUT] end check subType list --
    11:33:51,894 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,894 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,894 INFO  [STDOUT] end check subType list --
    11:33:51,895 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,896 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,896 INFO  [STDOUT] end check subType list --
    11:33:51,896 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,897 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,897 INFO  [STDOUT] end check subType list --
    11:33:51,899 INFO  [STDOUT] get subType list <<<<<<<<<<<<<<<<<<<<
    11:33:51,899 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,899 INFO  [STDOUT] end get subType list --
    11:33:51,900 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,901 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,901 INFO  [STDOUT] end check subType list --
    11:33:51,902 INFO  [STDOUT] check subType list ???????????????????
    11:33:51,902 INFO  [STDOUT] subType list current count filter: 3
    11:33:51,902 INFO  [STDOUT] end check subType list --
    On voit bien que le INFO [STDOUT] get subType list <<<<<<<<<<<<<<<<<<<< qui montre que l'on rempli les items de la liste des sous-catégorie.

    Message console sur une sélection d'une catégorie:
    Code : 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
     
    11:36:04,616 INFO  [STDOUT] Hibernate: 
        select
            type0_.typeId as typeId150_,
            type0_.typeName as typeName150_ 
        from
            evercat.type type0_ limit ?
    11:36:04,620 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,621 INFO  [STDOUT] Hibernate: 
        select
            count(subtype0_.subTypeId) as col_0_0_ 
        from
            evercat.subType subtype0_ limit ?
    11:36:04,622 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,622 INFO  [STDOUT] end check subType list --
    11:36:04,624 INFO  [STDOUT] Hibernate: 
        select
            subtype0_.subTypeId as subTypeId140_,
            subtype0_.subTypeName as subTypeN2_140_,
            subtype0_.typeId as typeId140_ 
        from
            evercat.subType subtype0_ limit ?
    11:36:04,626 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,626 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,626 INFO  [STDOUT] end check subType list --
    11:36:04,638 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,638 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,638 INFO  [STDOUT] end check subType list --
    11:36:04,639 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,639 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,639 INFO  [STDOUT] end check subType list --
    11:36:04,649 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,650 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,650 INFO  [STDOUT] end check subType list --
    11:36:04,650 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,651 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,651 INFO  [STDOUT] end check subType list --
    11:36:04,659 INFO  [STDOUT] refresh subType list ******************
    11:36:04,659 INFO  [STDOUT] -> id Type:1
    11:36:04,659 INFO  [STDOUT] restrictions
    11:36:04,659 INFO  [STDOUT] updated restrictions
    11:36:04,662 INFO  [STDOUT] Hibernate: 
        select
            count(subtype0_.subTypeId) as col_0_0_ 
        from
            evercat.subType subtype0_ 
        where
            subtype0_.typeId=? limit ?
    11:36:04,662 INFO  [STDOUT] refresh subType list end count filter: 2
    11:36:04,679 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,680 INFO  [STDOUT] subType list current count filter: 2
    11:36:04,680 INFO  [STDOUT] end check subType list --
    11:36:04,682 INFO  [STDOUT] Hibernate: 
        select
            subtype0_.subTypeId as subTypeId140_,
            subtype0_.subTypeName as subTypeN2_140_,
            subtype0_.typeId as typeId140_ 
        from
            evercat.subType subtype0_ 
        where
            subtype0_.typeId=? limit ?
    Ici la méthode refreshSubTypeList() est bien appellée mais aucun appel à getSubTypeList() pourtant on abien les appels à checkSubTypeList()?

    Message console sur une sélection d'une autre catégorie:
    Code : 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
     
    11:36:04,616 INFO  [STDOUT] Hibernate: 
        select
            type0_.typeId as typeId150_,
            type0_.typeName as typeName150_ 
        from
            evercat.type type0_ limit ?
    11:36:04,620 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,621 INFO  [STDOUT] Hibernate: 
        select
            count(subtype0_.subTypeId) as col_0_0_ 
        from
            evercat.subType subtype0_ limit ?
    11:36:04,622 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,622 INFO  [STDOUT] end check subType list --
    11:36:04,624 INFO  [STDOUT] Hibernate: 
        select
            subtype0_.subTypeId as subTypeId140_,
            subtype0_.subTypeName as subTypeN2_140_,
            subtype0_.typeId as typeId140_ 
        from
            evercat.subType subtype0_ limit ?
    11:36:04,626 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,626 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,626 INFO  [STDOUT] end check subType list --
    11:36:04,638 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,638 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,638 INFO  [STDOUT] end check subType list --
    11:36:04,639 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,639 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,639 INFO  [STDOUT] end check subType list --
    11:36:04,649 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,650 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,650 INFO  [STDOUT] end check subType list --
    11:36:04,650 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,651 INFO  [STDOUT] subType list current count filter: 3
    11:36:04,651 INFO  [STDOUT] end check subType list --
    11:36:04,659 INFO  [STDOUT] refresh subType list ******************
    11:36:04,659 INFO  [STDOUT] -> id Type:2
    11:36:04,659 INFO  [STDOUT] restrictions
    11:36:04,659 INFO  [STDOUT] updated restrictions
    11:36:04,662 INFO  [STDOUT] Hibernate: 
        select
            count(subtype0_.subTypeId) as col_0_0_ 
        from
            evercat.subType subtype0_ 
        where
            subtype0_.typeId=? limit ?
    11:36:04,662 INFO  [STDOUT] refresh subType list end count filter: 1
    11:36:04,679 INFO  [STDOUT] check subType list ???????????????????
    11:36:04,680 INFO  [STDOUT] subType list current count filter: 1
    11:36:04,680 INFO  [STDOUT] end check subType list --
    11:36:04,682 INFO  [STDOUT] Hibernate: 
        select
            subtype0_.subTypeId as subTypeId140_,
            subtype0_.subTypeName as subTypeN2_140_,
            subtype0_.typeId as typeId140_ 
        from
            evercat.subType subtype0_ 
        where
            subtype0_.typeId=? limit ?
    Ici je comprends encore moins la taille de la liste subTypeList devrait être à 2 au début et non à 3, compte tenue de la dernière sélection.

    Alors la je suis largué
    Aidez moi s'il vous plait

    Mon environnement:
    jboss-seam-2.2.0.GA
    jboss-5.1.0.GA

  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
    dans a4j:support, du moins dans la dérnière version release, il n'existe pas de reRenderAfterComplete, utilise reRender:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <a4j:support event="onchange" reRender="productSubType" action="#{productList.refreshSubTypeList}"/>
    et le composant à rafraichir doit être présent au rendu de la page, donc il faut faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    <a4j:outputPanel id="productSubType">
     
    <h:selectOneMenu rendered="#{not empty productList.checkSubTypeList.resultList}" value="#{productList.product.productSubType.subTypeId}">
    <s:selectItems value="#{productList.subTypeList.resultList}" var="subType" label="#{subType.subTypeName}" itemValue="#{subType.subTypeId}" noSelectionLabel="" />
    </h:selectOneMenu>
    </a4j:outputPanel>

  3. #3
    Membre averti
    Inscrit en
    Janvier 2010
    Messages
    12
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 12
    Par défaut
    Merci ça fonctionne parfaitement maintenant.

    Par contre l'attribut reRenderAfterComplete m'ai proposé en utilisant l'auto-complétion dans Eclipse, mais bon comme reRender fait le boulot autant l'utiliser.

  4. #4
    Membre du Club
    Inscrit en
    Avril 2010
    Messages
    8
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Avril 2010
    Messages : 8
    Par défaut Valeur null depuis un SelectOneMenu
    Bonjour,

    Je travaille avec JSF 2 et un peu de Ajax

    J'ai deux combos. Le choix du premier combo permet de choisir les valeurs pour remplir de deuxième. J'arrive à remplir le combo mais lorsque j'envoie le form, le bean n'arrive pas à mapper la valeur du deuxième combo et me retourne toujours null.

    Mes deux combos sont

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <h:selectOneMenu required="true" id="thread"
    						value="#{bRebatche.thread}" title="Thread">
    						<f:selectItems value="#{bSuspicious.lstThreads}" />
    						<f:ajax render="qoAvant" />
    					</h:selectOneMenu>					<h:selectOneMenu id="qoAvant" value="#{bRebatche.qoAvant}" binding="#{bRebatche.cmbQualiteAvant}"
    						disabled="#{bRebatche.qoAvantDisabled}" required="true" valueChangeListener="#{bRebatche.changeQo}"
    						requiredMessage="Erreur Validation. Qualité Avant. Valuer requise"
    						title="Qualité avant" style="width: 150" immediate="true">
    						<f:selectItems value="#{bRebatche.codes}" />
    						<f:ajax/>
    					</h:selectOneMenu></td>
    J'ai essayé avec un listener, avec un value pour le combo; avec un HtmlSelectOneMenu comme binding, mais j'arrive pas à afficher aach.

    Mon bean..

    Code : 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
    @ManagedBean
    public class BRebatche {
     
    	private transient HtmlSelectOneMenu 		cmbQualiteAvant	= new HtmlSelectOneMenu();
    	private transient HtmlSelectOneMenu 		cmbThread	= new HtmlSelectOneMenu();
     
    	private static List<Suspicious>			lstRebatche	= null;
     
    	public String getThread() {
    		return thread;
    	}
    	public void setThread(String thread) {
    		this.thread = thread;
    		isQoAvantDisabled = (this.thread==null);
    	}
    	public boolean isQoAvantDisabled() {
    		return isQoAvantDisabled;
    	}
    	public void setQoAvantDisabled(boolean isQoAvantDisabled) {
    		this.isQoAvantDisabled = isQoAvantDisabled;
    	}
    	public String getQoAvant() {
    		return qoAvant;
    	}
    	public void setQoAvant(String qoAvant) {
    		this.qoAvant = qoAvant;
    	}
    	public void changeQo(ValueChangeEvent event) {
    		System.out.println(event.getNewValue().toString());
    		qoAvant = event.getNewValue().toString();
     	}
    	public List<SelectItem> getCodes() {
    	    List<SelectItem> items = new ArrayList<SelectItem>();
    	    items.add(new SelectItem(null, "Choisissez"));
    	    if(!isQoAvantDisabled && (thread != null)) {
    	      if("4".equals(thread)){
     
    	      }else{
    	    	  items = BSuspicious.getLstMelange();
    	      }
    	    }
    	    return items;
    	  }
    	public void saveRegister(){
    		//ICI J'AI TOUT NULL
     
    		System.out.println(this.qoAvant);
    		System.out.println(this.cmbQualiteApres.getValue());
    	}
    Please... si y a qqun qui peut m'aider... tout fonctionnait bien jusqu'à ce qu'on m'a demandé de faire la relation entre ces deux combos...


+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 04/02/2013, 18h46
  2. définir un menu contextuel sur les items d'un treeview
    Par maa dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 05/05/2008, 19h51
  3. [Infobulle]sur les item d'une liste déroulante
    Par mamiberkof dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 24/05/2007, 11h31
  4. Réponses: 8
    Dernier message: 09/05/2007, 00h35
  5. dataTable et methode sur les items
    Par mereyj dans le forum JSF
    Réponses: 2
    Dernier message: 27/03/2007, 10h08

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