Bonjour à tous et merci à la communauté pour les aides que vous apportez à travers vos différentes discussion.
Je suis entrain de réaliser un petit formulaire en JSP en utilisant les composants RichFaces.
Ce morceau de code a pour but de créer une entreprise dans une base de donnée.
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 <h:form> <div class="zoneEditor"> <h:panelGrid columns="2"> .... </h:panelGrid> </div> <div class="zoneEditor"> <h:panelGrid columns="4"> .... </h:panelGrid> <h:panelGrid columns="2"> .... </h:panelGrid> <%-- PARTIE VILLE --%> <%--<a4j:outputPanel layout="block">--%> <h:panelGrid columns="3"> <a4j:outputPanel layout="block"> <%-- <h:form id="test"> --%> <h:outputText value="Code postal : "/> <h:inputText id="codePostal" label="codePostal" value="#{companymb.city.codePostal}"> <f:validateLength maximum="5" minimum="4"/> <a4j:support event="onchange" reRender="out2" /> </h:inputText> <%-- </h:form> --%> </a4j:outputPanel> <a4j:outputPanel id="out2" ajaxRendered="true"> Ville : <h:outputText id="ville" rendered="#{not empty companymb.city.codePostal}" value="#{companymb.test}" /> </a4j:outputPanel> <a4j:outputPanel ajaxRendered="true"> <h:message for="codePostal" style="color:red" /> </a4j:outputPanel> <%-- </a4j:outputPanel>--%> </h:panelGrid> <%-- FIN PARTIE VILLE --%> <h:panelGrid columns="4"> ..... </h:panelGrid> </div> <div class="zoneButton"> <h:commandButton type="submit" action="#{companymb.createCompany}" value="Ajouter cette entreprise"/> </div> </h:form>
Ce qui me pose problème c'est la partie ville. En gros, l'utilisateur rentre le code postal de l'entreprise et je retrouve le nom de la ville (grâce à #{companymb.test}) que j'affiche.
Donc dès que l'utilisateur à taper les 4 ou 5 chiffres du code postal et qu'il quitte le champ "codePostal", j'affiche la ville si je la trouve (sinon renvoie d'un message d'erreur).
Or le "reRender="out2" ne se fait pas et j'ai pas d'idée du pourquoi.
J'ai essayé de mettre la partie ville, à l'extérieur du form actuel et réactivé les balises form qui sont en commentaire et la ça fonctionne.
Ma question est donc comment faire fonctionner le reRender dans mon formulaire original et sans le mettre à l'extérieur du form ?
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 <h:form> <div class="zoneEditor"> <h:panelGrid columns="2"> .... </h:panelGrid> </div> <div class="zoneEditor"> <h:panelGrid columns="4"> .... </h:panelGrid> <h:panelGrid columns="2"> .... </h:panelGrid> <h:panelGrid columns="4"> ..... </h:panelGrid> </div> <div class="zoneButton"> <h:commandButton type="submit" action="#{companymb.createCompany}" value="Ajouter cette entreprise"/> </div> </h:form> <%-- PARTIE VILLE --%> <%--<a4j:outputPanel layout="block">--%> <h:panelGrid columns="3"> <a4j:outputPanel layout="block"> <h:form id="test"> <h:outputText value="Code postal : "/> <h:inputText id="codePostal" label="codePostal" value="#{companymb.city.codePostal}"> <f:validateLength maximum="5" minimum="4"/> <a4j:support event="onchange" reRender="out2" /> </h:inputText> </h:form> </a4j:outputPanel> <a4j:outputPanel id="out2" ajaxRendered="true"> Ville : <h:outputText id="ville" rendered="#{not empty companymb.city.codePostal}" value="#{companymb.test}" /> </a4j:outputPanel> <a4j:outputPanel ajaxRendered="true"> <h:message for="codePostal" style="color:red" /> </a4j:outputPanel> <%-- </a4j:outputPanel>--%> </h:panelGrid> <%-- FIN PARTIE VILLE --%> <%-- CE CODE FONCTIONNE --%>
Merci de vos réponses.
Partager