Salut
Je ne comprends pas ce qui va mal ...
Avec cette managed 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public class Toto implements Serializable { /** * */ private static final long serialVersionUID = -8146181369829766354L; /** * */ private Long id; /** * */ private String name; /** * @return */ public Long getId() { return id; } /** * @param id */ public void setId(Long id) { this.id = id; } /** * @return */ public String getName() { return name; } /** * @param name */ public void setName(String name) { this.name = name; } @Override public boolean equals(Object obj) { if(obj == null) return false; if(!(obj instanceof Toto)) return false; Long test1 = this.id; Long test2 = ((Toto)obj).getId(); return test1.equals(test2); } @Override public int hashCode() { int hash = 1; return hash * 31 + name.hashCode(); } }
et le JSF :
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 @ManagedBean @SessionScoped public class TestData implements Serializable { /** * */ private static final long serialVersionUID = 773591323733815749L; public List<Toto> getListTotos(){ List<Toto> list = new ArrayList<Toto>(); Toto t1 = new Toto(); t1.setId(1l); t1.setName("toto1"); list.add(t1); Toto t2 = new Toto(); t2.setId(2l); t2.setName("toto2"); list.add(t2); Toto t3 = new Toto(); t3.setId(3l); t3.setName("toto3"); list.add(t3); return list; } public void onEditRow(RowEditEvent event) { Toto editedCar = (Toto) event.getObject(); System.out.println(editedCar.getId()); System.out.println(editedCar.getName()); System.out.println(); //persist to database } }
Le problème est quand je valide la modification de ce champ :
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 <p:dataTable var="toto" value="#{testData.listTotos}" rowEditListener="#{testData.onEditRow}" > <f:facet name="header"> Toto list </f:facet> <p:column headerText="Options" style="width:50px"> <p:rowEditor /> </p:column> <p:column style="width:450px" headerText="RECIPIENT" footerText="exact" filterMatchMode="exact"> <p:cellEditor> <f:facet name="output"> <h:outputText value="#{toto.id}" /> </f:facet> <f:facet name="input"> <h:inputText value="#{toto.id}" /> </f:facet> </p:cellEditor> </p:column> <p:column style="width:450px" headerText="RECIPIENT" footerText="exact" filterMatchMode="exact"> <p:cellEditor> <f:facet name="output"> <h:outputText value="#{toto.name}" /> </f:facet> <f:facet name="input"> <h:inputText value="#{toto.name}" /> </f:facet> </p:cellEditor> </p:column> </p:dataTable>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2<h:inputText value="#{toto.name}" />
J'ai toujours dans mon écouteur d'événement la valeur de l'objets anciens: ??!! (pour quoi elle n'est pas modifier) (peu être je n'utilise pas le bonne listnere ?)
en plus le problème aussi ces que je n'est pas de message d'erreur notable (je suis dans le flous)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Toto editedCar = (Toto) event.getObject(); System.out.println(editedCar.getId()); System.out.println(editedCar.getName());
Merci
Partager