Bonjour à tous, je débute avec JSF (que je couple avec spring et hibernate) pour un projet.
J'ai deux tables Groupement et Localite liées par une relation un à plusieurs: un Groupement possède une et une seule localité. A une localité correspond plusieurs groupements.
Sur mon formulaire de création de Groupement je sélectionne la localité via un combo. (selectOneMenu)
Jusque la j'arrive à afficher les données de la base dans le selectOneMenu.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <h:outputLabel value="Localité" for="cbprofondeur" /><h:selectOneMenu id="cblocalite" value="#{groupementBean.currentGp.localite}" > <f:selectItems value="#{localiteBean.listeLoc}" var="loc" itemValue="#{loc.idlocalite}" itemLabel="#{loc.libelle}" /> </h:selectOneMenu> </h:panelGrid> <h:panelGroup> <h:commandButton value="Enregistrer" action="#{groupementBean.saveGp}" /> <h:commandButton value="Liste des groupements" action="#{groupementBean.listeGroupement}" immediate="true" />
Mon problème est que quand je valide mon enregistrement les données ne sont pas postées. J'ai fait pas mal de forums, mais je trouve pas solution.
Quelqu'un pourrait m'aider svp?
Classe GroupementBean
Classe LocaliteBean
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 ackage web; import java.io.Serializable; import java.util.List; import modele.Groupement; import modele.Links; import modele.service.GroupementSvc; import org.richfaces.component.html.HtmlScrollableDataTable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @SuppressWarnings("serial") @Component("groupementBean") @Scope("session") public class GroupementBean implements Serializable{ @Autowired private transient GroupementSvc groupementSvc; private transient HtmlScrollableDataTable gpTable; private Groupement currentGp; private List<Groupement> listeGp; public GroupementSvc getGroupementSvc() { return groupementSvc; } public void setGroupementSvc(GroupementSvc groupementSvc) { this.groupementSvc = groupementSvc; } public HtmlScrollableDataTable getGpTable() { return gpTable; } public void setGpTable(HtmlScrollableDataTable gpTable) { this.gpTable = gpTable; } public Groupement getCurrentGp() { return currentGp; } public void setCurrentGp(Groupement currentGp) { this.currentGp = currentGp; } public List<Groupement> getListeGp() { return listeGp; } public void setListeGp(List<Groupement> listeGp) { this.listeGp = listeGp; } //Methodes pour les liens des pages et les services metier public String createGroupement(){ currentGp = new Groupement(); return Links.createGroupement.toString(); } public String listeGroupement(){ init(); return Links.listeGroupement.toString(); } public void init(){ listeGp = groupementSvc.listGroupements(); } public String saveGp(){ groupementSvc.addGroupement(currentGp); return listeGroupement();//createGroupement(); } }
Cordialement
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 package web; import java.io.Serializable; import java.util.List; import javax.annotation.PostConstruct; import modele.Links; import modele.Localite; import modele.service.LocaliteSvc; import org.richfaces.component.html.HtmlScrollableDataTable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @SuppressWarnings("serial") @Component("localiteBean") @Scope("session") public class LocaliteBean implements Serializable{ @Autowired private transient LocaliteSvc locSvc; private transient HtmlScrollableDataTable locTable; private Localite currentLoc; private List<Localite> locListe; @PostConstruct public void init(){ locListe = locSvc.listLocalite(); } public LocaliteSvc getLocSvc() { return locSvc; } public void setLocSvc(LocaliteSvc locSvc) { this.locSvc = locSvc; } public HtmlScrollableDataTable getLocTable() { return locTable; } public void setLocTable(HtmlScrollableDataTable locTable) { this.locTable = locTable; } public Localite getCurrentLoc() { return currentLoc; } public void setCurrentLoc(Localite currentLoc) { this.currentLoc = currentLoc; } public List<Localite> getLocListe() { return locListe; } public void setLocListe(List<Localite> locListe) { this.locListe = locListe; } /*Link & Pages methods*/ public String createLocalite(){ currentLoc = new Localite(); return Links.createLocalite.toString(); } public void dropLocalite(int id){ } public String saveLoc(){ locSvc.saveLocalite(currentLoc); init(); return createLocalite(); } }
Partager