Salut,
je suis en train d'apprendre à utiliser jsf tout seul et je suis confronté à un comportement bizarre venant de ma page:
Je créé un formulaire dynamiquement constitué de lignes de course .
Quand je modifie une ligne, il faut que je click 2 fois sur le bouton "changer" pour que la mise à jour s'effectue. Ensuite, si je refais une modif sur la même ligne, la modif est prise en compte au premier coup.
voici les codes de ma page et de 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 <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title>Formulaire dynamique</title> </h:head> <h:body> <h:panelGroup id="rootForm"> <ui:repeat value="#{formuBean.listeCourse}" var="element"> <h:form> <h:inputHidden id="id" value="#{element.num}"/> <h:inputText id="texte" value="#{element.elem}"/> <h:inputText id="nb" value="#{element.nb}"/> <h:commandButton value="Changer"> <f:ajax execute="@form" render=":sortie" listener="#{formuBean.changeElem()}"/> </h:commandButton> <h:commandButton value="Supprimer la ligne"> <f:ajax execute="@form" render=":sortie" listener="#{formuBean.supprElem()}"/> </h:commandButton> <br/> </h:form> </ui:repeat> <h:form> <h:commandButton value="Ajouter une ligne"> <f:ajax render=":rootForm :sortie" listener="#{formuBean.ajouteElem()}"/> </h:commandButton> </h:form> </h:panelGroup> <br/> <h:panelGroup id="sortie"> <ui:repeat value="#{formuBean.listeCourse}" var="element"> #{element.num} #{element.elem} #{element.nb} <br/> </ui:repeat> </h:panelGroup> </h:body> </html>Est-ce que qq1 pourrait me dire comment je pourrais normaliser ce comportement?
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 @ManagedBean @SessionScoped public class formuBean { public formuBean() { } LinkedList<Element> listeCourse = new LinkedList<Element>(); Integer id; String texte; Integer nb; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getNb() { return nb; } public void setNb(Integer nb) { this.nb = nb; } public String getTexte() { return texte; } public void setTexte(String texte) { this.texte = texte; } public LinkedList<Element> getListeCourse() { return listeCourse; } public void ajouteElem(){ listeCourse.add(new Element(listeCourse.size()+1, "", 0)); } public void changeElem(){ Integer index; for(Element i:listeCourse){ if(i.num==this.id){ index=listeCourse.indexOf(i); listeCourse.get(index).setNb(this.nb); listeCourse.get(index).setElem(this.texte); } } } public void supprElem(){ for(Element i:listeCourse){ if(i.num==this.id){ listeCourse.remove(listeCourse.indexOf(i)); } } } }
Si vous avez des remarque sur la façon dont j'aborde le problème ou s'il existe une autre façon de faire avec JSF, lâchez-vous...![]()
Partager