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 :

récupérer valeur a4j:commandlink dans backing bean


Sujet :

JSF Java

  1. #1
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut récupérer valeur a4j:commandlink dans backing bean
    Salut,

    Voilà dans ma page JSP j'ai un a4j:commandlink avec une certaine valeur, je voudrais récupérer cette dernière dans mon backing bean, voici ce que j'ai écrit dans ma page jsp et mon backing bean:

    JSP:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <a4j:commandLink id="lien" value="#{node}"  immediate="true" 
    							oncomplete="Richfaces.showModalPanel('popNoeud',{width:'400',height:'300'});" />
    Java:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    UIComponent monLink = (UIComponent) FacesContext
    		.getCurrentInstance().getViewRoot().findComponent("Administration:lien");
        	System.out.println("%%%%%%%%%%%%%%%%%%%  mon lnk "+monLink); 
    monLink.getAttributes().get("value").toString();
    tq "Administration" est l'id du formulaire conteneur.
    De cette façon "monLink" me retourne toujours null.

    Comment corriger ça svp?

    Merci
    Cherchez le savoir jusqu'en Chine !

  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
    Points : 5 059
    Points
    5 059
    Par défaut
    enlève immédiate, lorsqu'il est à true la valeur n'est pas envoyée.

  3. #3
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    Salut,
    ça ne marche toujours pas, voici le code complet de ma page 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
    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
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Création menu</title>
     
    </head>
    <body>
    <f:view>
    	<a4j:form id="Administration">
     
    		<rich:panel id="pun" header="Administartion">
    			<rich:toolBar height="26" itemSeparator="grid" width="100%">
    				<rich:toolBarGroup>
    					<a4j:commandLink id="Icreate" action="#{EBAdministration.insertMenu}"
    						ajaxSingle="true">
    						<h:graphicImage value="/Images/save.gif" styleClass="pic"
    							style="border:0; height : 15px;" />
    					</a4j:commandLink>
    					<a4j:commandLink id="Iaffect" action="#{EBAdministration.insertProfileGroupe}">
    						<h:graphicImage value="/Images/refresh.png" styleClass="pic"
    							style="border:0;" />
    					</a4j:commandLink>
    				</rich:toolBarGroup>
    				<rich:toolBarGroup location="right">
    					<h:graphicImage value="/Images/filter.gif" styleClass="pic" />
    					<h:graphicImage value="/Images/help.png" styleClass="pic" />
    				</rich:toolBarGroup>
    			</rich:toolBar>
     
    				<table width="100%">
    					<tr>
    						<td class="HEADL" width="15%">Code menu</td>
    						<td width="30%" class="BODY"><h:inputText id="code"
    							value="#{EBAdministration.selectedMenu.codeMenu}" size="10" maxlength="5"
    							required="" styleClass="FONT"></h:inputText> 						
    						</td>
    						<td width="15%" class="HEADL">Libelle menu</td>
     
    						<td width="50%" class="BODY"><h:inputText 
    							value="#{EBAdministration.selectedMenu.libelle}" size="54" maxlength="80"
    							styleClass="FONT" >
    							<a4j:support event="onblur" actionListener="#{EBAdministration.createCurseur}" reRender="arbre"></a4j:support>
     
     
    							</h:inputText></td>
    						<td width="15%" class="HEADL">Code groupe</td>
     
    						<td width="50%" class="BODY"><h:inputText
    							value="#{EBAdministration.selectedGroupe.codeGroupe}" size="54" maxlength="80"
    							styleClass="FONT" />
    						<a4j:commandLink
    							oncomplete="Richfaces.showModalPanel('popGroupe',{width:'360',height:'300'});"
    							ajaxSingle="true">
    							<img src="/Images/loupe.gif" width="16" height="16" border="0">
    						</a4j:commandLink></td>
    					</tr>
    				</table>
     
     
    			  <!-- drag zone -->
    			  <rich:dataGrid value="#{EBAdministration.lmasqueDM}" var="masque" columns="1">
    			  	 <a4j:outputPanel layout="block" style="cursor: move"> 
        				<rich:dragSupport dragType="masque" dragValue="#{masque}" > 
        					<rich:dndParam name="label" value="#{masque.libelle}" /> 
          				</rich:dragSupport>
          				<h:outputText value="#{masque.libelle}" /> 
      				</a4j:outputPanel> 			  	  
    			  </rich:dataGrid>
     
    				  	  <!-- drop zone -->
     
     
      				<rich:dropSupport acceptedTypes="masque" dropListener="#{EBAdministration.onDropItem}" 
          				reRender="Administration" dropValue="arbre" /> 
      				<br/>
      				<rich:tree id="arbre" adviseNodeOpened="true" switchType="client" 
      					value="#{EBAdministration.arbre2}" var="node">					
    					<rich:treeNode id="nod" ajaxSubmitSelection="true" >
     
     
    						<a4j:commandLink id="lien" value="#{node}"  immediate="false"
    							oncomplete="Richfaces.showModalPanel('popNoeud',{width:'400',height:'300'});" >
    							<h:inputHidden id="nd" value="#{node}" binding="#{EBAdministration.selectedNode}"/>
     
    						</a4j:commandLink>
     
    					</rich:treeNode>
           			  </rich:tree>
    				 </rich:panel>
           			</a4j:form>
     
    			<a4j:form>
     
    		<!-- Affichage de la POP UP Groupe -->
    		<rich:modalPanel id="popGroupe">
    			<rich:dataTable onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
    				onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
    				value="#{EBAdministration.lgroupeDM2}" var="G" rowKeyVar="row" rows="5"
    				reRender="ds" id="tableG">
    				<f:facet name="header">
    					<rich:columnGroup>
    						<rich:column colspan="3">
    							<h:outputText value="Liste des Groupes" />
    						</rich:column>
    						<rich:column breakBefore="true">
    							<f:facet name="header">
    								<h:outputText value=" "
    									title="Hack due to bug. Shuold be remoevd till release"></h:outputText>
    							</f:facet>
    							<h:outputText value="codeGroupe" />
    						</rich:column>
    						<rich:column >
    							<h:outputText value="libelleGroupe" />
    						</rich:column>
     
    					</rich:columnGroup>
    				</f:facet>
    				<rich:column filterBy="#{G.codeGroupe}" filterEvent="onkeyup">
     
    					<h:outputText value="#{G.codeGroupe}" />
    				</rich:column>
    				<rich:column filterBy="#{G.libelle}" filterEvent="onkeyup">
     
    					<h:outputText value="#{G.libelle}" />
    				</rich:column>
    				<f:facet name="footer">
    					<rich:datascroller id="ds" renderIfSinglePage="false"></rich:datascroller>
    				</f:facet>
     
    				<a4j:support event="onRowClick"
    					oncomplete="Richfaces.hideModalPanel('popGroupe');" reRender="Administration">
    					<f:setPropertyActionListener value="#{G}"
    						target="#{EBAdministration.selectedGroupe}" />
    				</a4j:support>
     
    			</rich:dataTable>
    		</rich:modalPanel>
    		</a4j:form>
    		<a4j:form>
    		<!-- Affichage de la POP UP Noeud -->
    		<rich:modalPanel id="popNoeud">
    			<table width="100%">
    				<tr>
    					<td>
    					<h:outputText id ="o1" value="Code sous menu" /><h:inputText id="i2" value="#{EBAdministration.selectedSubMenuPK.codeSubMenu}" />
    					</td>
    					<td>
    					<h:outputText id ="o2" value="Libelle sous menu" /><h:inputText id="i1" value="#{EBAdministration.selectedSubMenu.libelle}" />
    					</td>
    					<td>
    					<a4j:commandLink id="mi1" action="#{EBAdministration.insertNoeud}"
    						ajaxSingle="true" oncomplete="Richfaces.hideModalPanel('popGroupe');" reRender="Administration">
     
    						<h:outputText value="ajouter un noeud" />
    					</a4j:commandLink>
    					</td>
    				</tr>
    			</table>
    		</rich:modalPanel>
    	</a4j:form>
     
    </f:view>
    </body>
    </html>
    la balise a4j:commandlink> n'est pas l'enfant direct de la form, est ce que ça pose problème pour retrouver le composant?

    Merci
    Cherchez le savoir jusqu'en Chine !

  4. #4
    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
    Points : 5 059
    Points
    5 059
    Par défaut
    et n'utilise pas ajaxSingle.

  5. #5
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    Je n'ai pas mis ajaxSingle dans mon commandlink
    Cherchez le savoir jusqu'en Chine !

  6. #6
    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
    Points : 5 059
    Points
    5 059
    Par défaut
    et ça ..?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <a4j:commandLink id="Icreate" action="#{EBAdministration.insertMenu}"
    ajaxSingle="true">

  7. #7
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    ce n'est pas le command link duquel je veux récupérer la valeur, pourquoi ça peut influencer?
    Cherchez le savoir jusqu'en Chine !

  8. #8
    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
    Points : 5 059
    Points
    5 059
    Par défaut
    Citation Envoyé par trin86 Voir le message
    ce n'est pas le command link duquel je veux récupérer la valeur, pourquoi ça peut influencer?
    lequel alors??
    évite d'utiliser plusieurs form dans la page,
    englobe tous tes composants d'un seul a4j:form.

  9. #9
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    J'ai englobé toute la page dans un même <a4j:form> mais ça ne change rien, j'ai toujours mon composant null.
    Cherchez le savoir jusqu'en Chine !

  10. #10
    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
    Points : 5 059
    Points
    5 059
    Par défaut
    tu peux donner le code du commandLink qui ne fonctionne pas.?

  11. #11
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    Voilà la partie qui ne fonctionne pas:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    <rich:tree id="arbre" adviseNodeOpened="true" switchType="client" 
      					value="#{EBAdministration.arbre2}" var="node">					
    					<rich:treeNode id="nod" ajaxSubmitSelection="true" >
     
     
    						<a4j:commandLink id="lien" value="#{node}"  
    							oncomplete="Richfaces.showModalPanel('popNoeud',{width:'400',height:'300'});" >
    							<h:inputHidden id="nd" value="#{node}" binding="#{EBAdministration.selectedNode}"/>
     
    						</a4j:commandLink>
     
    					</rich:treeNode>
           			  </rich:tree>
    Cherchez le savoir jusqu'en Chine !

  12. #12
    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
    Points : 5 059
    Points
    5 059
    Par défaut
    - Si tu veux juste récupérer le node selectionné, regarde cet exemple.

    - Pour utiliser commandLink dans une tree, tu dois désactiver la sélection lors du submit à l'aide de ajaxSubmitSelection.

    - On n'utilise pas input hidden à l'interieur d'un commandLink, pour passer des paramètres avec le commandLink ou commandButton, utilise plutôt f:param ou a4j:actionparam.

  13. #13
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    Resalut,
    - Pour l'exemple, j'ai déjà essayé mais le nodeselectListener ne s'execute pas.
    - J'ai mis ajaxSubmitSelection à false, j'espère que c'est correct.
    - J'ai remplacé le inputHidden par un f:param de cette façon:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <rich:tree id="arbre" adviseNodeOpened="true" switchType="client" 
      					value="#{EBAdministration.arbre2}" var="node">					
    					<rich:treeNode id="nod" ajaxSubmitSelection="false" >
     
     
    						<a4j:commandLink id="lien" value="#{node}"  
    							oncomplete="Richfaces.showModalPanel('popNoeud',{width:'400',height:'300'});" >
    							<f:param id="select" name="select" value="#{node}"/>		
    						</a4j:commandLink>
     
    					</rich:treeNode>
           			  </rich:tree>
    , et je récupère le parametre de cette façon:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    selectedNoeud = (String) FacesContext.getCurrentInstance().getExternalContext()
        	    .getRequestParameterMap().get("select");
    Tout cela ne change rien n'au résultat, est ce que j'ai fait une erreur quelque part?
    merci
    Cherchez le savoir jusqu'en Chine !

  14. #14
    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
    Points : 5 059
    Points
    5 059
    Par défaut
    Si le nodeSelectListener ne s'exécute pas c'est que tu l'a mal implémenter ou que tu as oublié quelque chose. Par contre, ce que tu fais, n'a pas de grande chance de fonctionner parce que la tree ne fonctionne pas comme ça,

  15. #15
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    Désolée c'est la première fois que je travaille avec un tree donc c'est normal que je ne sache pas dutout comment ça fonctionne, j'attend juste que quelqu'un m'apprenne.
    Tout ce que je veux c'est que à chaque fois qu'un user clique sur le noeud il doit y avoir une pop up qui s'affiche pour introduire un nouveau noeud fils, et pour cela je dois récupérer le noeud parent. Comment l'implémenter? pour ça je suis perdue.
    Cherchez le savoir jusqu'en Chine !

  16. #16
    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
    Points : 5 059
    Points
    5 059
    Par défaut
    Citation Envoyé par trin86 Voir le message
    Désolée c'est la première fois que je travaille avec un tree donc c'est normal que je ne sache pas dutout comment ça fonctionne, j'attend juste que quelqu'un m'apprenne.
    Tout ce que je veux c'est que à chaque fois qu'un user clique sur le noeud il doit y avoir une pop up qui s'affiche pour introduire un nouveau noeud fils, et pour cela je dois récupérer le noeud parent. Comment l'implémenter? pour ça je suis perdue.
    tu peux t'inspirer des exemples de Richfaces, et de la documentation..
    un petit exemple que j'avais testé:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <rich:treeNode nodeSelectListener="#{treeBean.processUserSelection}">
    	<h:outputText value="#{item.lastname} #{item.firstname}" />
    </rich:treeNode>
    et le bean


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    public void processUserSelection(NodeSelectedEvent event) {
     
    		HtmlTree tree = (HtmlTree) event.getComponent().getParent();
     
    		BeanNode node = (BeanNode ) tree.getRowData();
                   ... 
                  }

  17. #17
    Membre du Club Avatar de trin86
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    171
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : Belgique

    Informations forums :
    Inscription : Décembre 2008
    Messages : 171
    Points : 63
    Points
    63
    Par défaut
    Merci pour ta réponse,

    j'ai suivi ton exemple en séparant le <a4j:commandlink> du treenode, comme ça il récupère d'abord le noeud séléctionné avec nodeselectevent; ensuite il clique sur le lien pour ajouter au noeud séléctionné un autre noeud. Ca fait plus propre et plus clair à l'execution.

    Merci
    Cherchez le savoir jusqu'en Chine !

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

Discussions similaires

  1. Récupérer variable de session dans un bean
    Par thefutureisnow dans le forum Débuter avec Java
    Réponses: 15
    Dernier message: 25/11/2009, 09h19
  2. récupérer valeur du javascript dans une variable php
    Par zoukman18 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 18/08/2009, 17h11
  3. a4j CommandLink dans un rich:tree
    Par saveThyCheerleader dans le forum JSF
    Réponses: 2
    Dernier message: 29/04/2009, 22h59
  4. Réponses: 21
    Dernier message: 22/05/2008, 16h51

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