Bonjour je developpe une application de gestion scolaire et j'ai différents problèmes sur ce formulaire.Bref pour le moment le problème c'est qu'aucun évènement ne se passe lors du clic sur le bouton d'insertion de l'entité EtablissementGlobal.
Avant cela un messagese faisait signaler sur le selectoneMenu de "section" et pas sur le reste et depuis plus rien.
Code : Sélectionner tout - Visualiser dans une fenêtre à part "d'erreur de validation:valeur incorrecte"
J'ai déjà debuggé pour voir si la conversion des converteurs est bonne c'est OK
J'ai écrit une classe de validation et j'ai pu constaté que j'ai bel et bien les instances d'objet au cycle de validation juste après la conversion
voici mes classes de persistances
EtablissementGlobal:Entité Pays
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 @Entity @Table(name = "EtablissementGlobal") public class EtablissementGlobal implements DAOEntry { @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column(name = "Id") private Long id; @Column(name = "Code",unique=true,nullable=false) private String code; @Size(max = 255) @Column(name = "Nom") private String nom; @Size(max = 255) @Column(name = "NomAnglais") private String nomAnglais; @Size(max = 100) @Column(name = "Devise") private String devise; @Size(max = 100) @Column(name = "DeviseAnglais") private String deviseAnglais; @Size(max = 200) @Column(name = "TypeResponsable") private String typeResponsable; @Embedded private Adresse adresse; @Column(name="SiteWeb") private String siteWeb; @Size(max = 50) @Column(name = "Couleur") private String couleur; @Size(max = 50) @Column(name = "Codification") private String codification; //specifie si le logo sera sur les etats @Column(name = "VoirLogos") private Boolean voirLogos; @Lob @Column(name = "Logos") private byte[] logos; @Size(max = 50) @Column(name = "Monnaie") private String monnaie; @Size(max = 50) @Column(name = "Division") private String division; @Column(name = "NbreDivision") private Integer nbreDivision; @Column(name = "PerSave") private String perSave; //Compresser la sauvegarde @Column(name = "ComprSave") private Boolean comprSave; @Column(name = "DateBackup") @Temporal(TemporalType.TIMESTAMP) private Date dateBackup; @Size(max = 50) @Column(name = "OrdisBackup") private String ordisBackup; //repertoire de backup @Size(max = 255) @Column(name = "RepBackupFile") private String repBackupFile; @Size(max = 10) @Column(name = "AppVersion") private String appVersion; @Size(max = 255) @Column(name = "NomResponsable") private String nomResponsable; @Column(name = "Actif") private Boolean actif; @Column(name = "DateEnregistrement") @Temporal(TemporalType.DATE) private Date dateEnregistrement; // @Column(name = "Cloture") // private Integer cloture; @JoinColumn(name = "pays_id", referencedColumnName = "Id") @ManyToOne(optional = false) private Pays codePays; @JoinColumn(name = "ministere_id", referencedColumnName = "Id") @ManyToOne(fetch=FetchType.LAZY,optional = false) private Ministeres codeMinistere; @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "etablissementGlobal") private Collection<Etablissements> EtablissementGlobals; @JoinColumn(name="section_id",referencedColumnName="Id") @OneToOne(fetch= FetchType.LAZY,optional=true) private Section codeSection; public Collection<Etablissements> getEtablissementGlobals() { return EtablissementGlobals; } public EtablissementGlobal(String code, String nom) { this.code = code; this.nom = nom; } //getters/setters }
entité ministère
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 @Entity @Table(name = "pays") public class Pays implements DAOEntry { public static final String FIND_ALL="Pays.findAll"; public static final String FIND_BY_CODE="Pays.findByCode"; public static final String FIND_BY_LIBELLE="Pays.findByLibelle"; public static final String FIND_BY_LIBELLE_ANGLAIS="Pays.findByLibelleAnglais"; private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column(name = "Id") private Long id; @Size(max = 50) @Column(name = "Code",unique=true,nullable=false) private String code; @Size(max = 255) @Column(name = "Libelle") private String libelle; @Size(max = 255) @Column(name = "LibelleAnglais") private String libelleAnglais; @Size(max = 50) @Column(name = "Continent") private String continent; @OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE}, mappedBy = "codePays") private Collection<EtablissementGlobal> etablissementsCollection; // @OneToMany(fetch=FetchType.LAZY,cascade = CascadeType.ALL, mappedBy = "codePays") // private Collection<Etudiant> etudiantCollection; public Pays() { } public Pays(String code) { this.code = code; } public Pays(String code, String libelle, String libelleAnglais, String continent) { this.code = code; this.libelle = libelle; this.libelleAnglais = libelleAnglais; this.continent = continent; } //getters et setters }
et l'entité Section
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 @Entity @Table(name = "ministeres") public class Ministeres implements DAOEntry { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column(name = "Id") private Long id; @Size(max = 50) @Column(name = "Code",unique=true,nullable=false) private String code; @Size(max = 50) @Column(name = "Sigle") private String sigle; @Size(max = 255) @Column(name = "Libelle") private String libelle; @Column(name = "Actif") private Boolean actif; @OneToMany(fetch=FetchType.LAZY,cascade = {CascadeType.PERSIST,CascadeType.MERGE}, mappedBy = "codeMinistere") private Collection<EtablissementGlobal> etablissementsCollection; public Ministeres() { } public Ministeres(String code) { this.code = code; } //getters/setters }
voici le controleur EtablissementGlobal
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 @Entity @Table(name="Section") public class Section implements DAOEntry{ @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column(name="Id") private Long id; @Size(max=30) @Column(name="libelle",unique=true,nullable=false) private String libelle; public Section(String libelle) { this.libelle = libelle; } public Section() { } //getters/setters }
enfin voici la page xhtml
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 @ManagedBean(name = "etabGlobalController") @SessionScoped public class EtabGlobalController implements Serializable { @EJB private EtablissementGlobalDao etagloDao; @EJB private MinisteresDao ministerDao; @EJB private SectionDao sectionDao; @EJB private PaysDao paysDao; private EtablissementGlobal etaglo; public EtabGlobalController() { etaglo = new EtablissementGlobal(); } public void init() { etaglo = new EtablissementGlobal(); } @PostConstruct void initialiseSession() { FacesContext.getCurrentInstance().getExternalContext().getSession(true); } Converter paysConverter =new Converter(){ @Override public Object getAsObject(FacesContext fc, UIComponent uic, String value) { try{ return paysDao.find(Long.valueOf(value)); } catch (Exception e) { throw new ConverterException(new FacesMessage(String.format("Cannot convert %s to Pays", value)), e); } } @Override public String getAsString(FacesContext fc, UIComponent uic, Object value) { //tu formalises l'affichage donc value ici est le pays return String.valueOf(((Pays)value).getId()); } }; Converter ministeresConverter =new Converter(){ @Override public Object getAsObject(FacesContext fc, UIComponent uic, String value) { try{ return ministerDao.find(new Long(value)); } catch (Exception e) { throw new ConverterException(new FacesMessage(String.format("Cannot convert %s to Ministeres", value)), e); } } @Override public String getAsString(FacesContext fc, UIComponent uic, Object value) { //tu formalises l'affichage donc value ici est le ministere return String.valueOf(((Ministeres) value).getId()); } }; Converter sectionConverter =new Converter(){ @Override public Object getAsObject(FacesContext fc, UIComponent uic, String value) { //tu dois retourne l'objet donc ici la section try{ return sectionDao.find(Long.valueOf(value)); } catch (Exception e) { throw new ConverterException(new FacesMessage(String.format("Cannot convert %s to Section",value)), e); } } @Override public String getAsString(FacesContext fc, UIComponent uic, Object value) { //tu formalises l'affichage donc value ici est la section return String.valueOf(((Section)value).getId()); } }; public String addEtabglo() { FacesContext ctx = FacesContext.getCurrentInstance(); try { //recherche si le pays existe if (etagloDao.findEntityHavingValue("code", etaglo.getCode()) == null) { etagloDao.create(etaglo); ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Info insert niveau", "l'etablissement " + etaglo.getNom() + " a ete cree avec succes")); } else { ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Erreur de doublons", "l'etablissement " + etaglo.getNom() + "existe deja")); } } catch (ConstraintViolationException E) { ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erreur insert", "une erreur est survenu " + E.getMessage() + " " + E.getCause())); throw E; } catch (Throwable th) { //ecrire dans le fichier de log ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Erreur insert", "une erreur est survenu " + th.getMessage() + " " + th.getCause() + "-" + th.getClass())); } this.init(); return null; } public EtablissementGlobal getEtaglo() { return etaglo; } public void setEtaglo(EtablissementGlobal etaglo) { this.etaglo = etaglo; } public MinisteresDao getMinisterDao() { return ministerDao; } public void setMinisterDao(MinisteresDao ministerDao) { this.ministerDao = ministerDao; } public PaysDao getPaysDao() { return paysDao; } public void setPaysDao(PaysDao paysDao) { this.paysDao = paysDao; } public SectionDao getSectionDao() { return sectionDao; } public void setSectionDao(SectionDao sectionDao) { this.sectionDao = sectionDao; } public EtablissementGlobalDao getEtagloDao() { return etagloDao; } public void setEtagloDao(EtablissementGlobalDao etagloDao) { this.etagloDao = etagloDao; } public Converter getSectionConverter() { return sectionConverter; } public Converter getMinisteresConverter() { return ministeresConverter; } public Converter getPaysConverter() { return paysConverter; } }
Code xml : 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 <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"> <ui:composition template="template/Template.xhtml"> <!-- <f:loadBundle basename="com.better.welcome" var="msg"/> --> <!-- <ui:define name="menugauche"> <ui:include src="template/menuGcheParam.xhtml"/> </ui:define>--> <ui:define name="contenu"> <f:view> <h:form id="form1"> <p:commandButton icon="ui-icon-disk" value="#{msg['bouton.ajouter']}" actionListener="#{etabGlobalController.addEtabglo}" update="grid,:form2:idEtabgloTable"/> <p:commandButton icon= "ui-icon-bookmark" value="#{msg['bouton.modifier']}" actionListener="#{etabGlobalController.updateEtabglo}" update="grid,:form2:idEtabgloTable"/> <br/> <br/> <p:messages autoUpdate="true" showDetail="true" showSummary="true"/> <p:panel header="#{msg['etabglo.label.Panel']}"> <h:panelGrid id="grid" columns="3" styleClass="noBorders"> <h:outputLabel value="#{msg['etabglo.label.code']}: " for="code" /> <p:inputText id="code" value="#{etabGlobalController.etaglo.code}" title="code" required="true"/> <p:message for="code" /> <h:outputLabel value="#{msg['etabglo.label.nom']}: " for="nom" /> <p:inputText id="nom" value="#{etabGlobalController.etaglo.nom}" title="nom" required="true"/> <p:message for="nom" /> <h:outputLabel value="#{msg['etabglo.label.nomA']}:" for="nomA" /> <p:inputText id="nomA" value="#{etabGlobalController.etaglo.nomAnglais}" title="nomA" /> <p:message for="nomA" /> <h:outputLabel value="#{msg['etabglo.label.devise']}: " for="devise" /> <p:inputText id="devise" value="#{etabGlobalController.etaglo.devise}" title="devise" /> <p:message for="devise" /> <h:outputLabel value="#{msg['etabglo.label.deviseA']}:" for="deviseA" /> <p:inputText id="deviseA" value="#{etabGlobalController.etaglo.deviseAnglais}" title="deviseA" /> <p:message for="deviseA" /> <h:outputLabel value="#{msg['etabglo.label.responsableType']}: " for="responsableT" /> <p:inputText id="responsableT" value="#{etabGlobalController.etaglo.typeResponsable}" title="responsableT" /> <p:message for="responsableT" /> <h:outputLabel value="#{msg['etabglo.label.Site']}: " for="Site" /> <p:inputText id="Site" value="#{etabGlobalController.etaglo.siteWeb}" title="Site" /> <p:message for="Site" /> <h:outputLabel value="#{msg['etabglo.label.couleur']}: " for="couleur" /> <p:inputText id="couleur" value="#{etabGlobalController.etaglo.couleur}" title="couleur" /> <p:message for="couleur" /> <h:outputLabel value="#{msg['etabglo.label.codification']}: " for="codification" /> <p:inputText id="codification" value="#{etabGlobalController.etaglo.codification}" title="codification" /> <p:message for="codification" /> <h:outputLabel value="#{msg['etabglo.label.pays']}: "/> <p:selectOneMenu value="#{etabGlobalController.etaglo.codePays}" id="pays" converter="#{etabGlobalController.paysConverter}"> <f:selectItems value="#{etabGlobalController.paysDao.allPays}" var="p" itemLabel="#{p.libelle}" itemValue="#{p}"/> </p:selectOneMenu> <br/> <h:outputLabel value="#{msg['etabglo.label.minist']} " /> <p:selectOneMenu value="#{etabGlobalController.etaglo.codeMinistere}" id="ministere" converter="#{etabGlobalController.ministeresConverter}"> <f:selectItems value="#{etabGlobalController.ministerDao.allMiniteres}" var="min" itemLabel="#{min.libelle}" itemValue="#{min}"/> </p:selectOneMenu> <br/> <h:outputLabel value="Section" /> <p:selectOneMenu value="#{etabGlobalController.etaglo.codeSection}" id="section" converter="#{etabGlobalController.sectionConverter}"> <f:selectItems value="#{etabGlobalController.sectionDao.allSection}" var="sec" itemLabel="#{sec.libelle}" itemValue="#{sec}"/> </p:selectOneMenu> <br/> <h:outputText value="#{msg['label.actif']}:" /> <p:selectBooleanButton value="#{etabGlobalController.etaglo.actif}" onLabel="Yes" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close"/> </h:panelGrid> </p:panel> </h:form> </f:view> </ui:define> </ui:composition> </html>
Merci d'avance pour votre aide!
Cordialement
Partager