Bonjour,
Je débute dans le fabuleux monde Java, et j'ai un soucis; Je suis sur un projet en JSF2 et JPA. Je veux afficher le résultat d'une requête. La liaison avec la table est bien effective car je crée ma table à partir de mes entités. J'ai un modèle Vue-Business-Dao, avec des Interfaces pour les Business et DAO. Le résultat de ma requête remonte bien jusqu'à mon ManagedBean, mais systématiquement, il trouve un problème et saute à l'affichage. Le soucis est que je ne vois pas le problème. Qui est peut être tout simple.
Je ne sais pas si je vais penser à tout vous joindre. Voici ma vue:
mon 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 <!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:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <ui:composition template="/MasterPage.xhtml"> <ui:define name="EspCss"> <h:outputStylesheet name="CSS/StyleAccueil.css"></h:outputStylesheet> <h:outputStylesheet name="CSS/Common.css"></h:outputStylesheet> </ui:define> <ui:define name="PrincipalContent"> <div class="article"> ICI SERONT LES OEUVRES <h:form> <p:dataTable value="#{mbWorks.oeuvres}" var="oeuvre"> <p:column headerText="Nom de l'oeuvre"> <h:outputLabel value="#{oeuvre.name}" /> </p:column> </p:dataTable> </h:form> #{mbWorks.oeuvres.size()} <!-- FONCTIONNE et renvoie bien une liste à 10 --> </div> </ui:define> </ui:composition> </html>
mon Business:
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 package fr.ov.beans; import java.util.List; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import fr.ov.JabDibbets.entities.Medium; import fr.ov.JabDibbets.entities.Oeuvre; import oeuvresIBusiness.OeuvresIBusiness; @ManagedBean (name="mbWorks") @ViewScoped public class WorksManagedBean { //TODO Prévoir un accès différencié pour l'admin? @EJB private OeuvresIBusiness proxyOeuvreBusiness; private List<Medium> mediums; private List<Oeuvre> oeuvres; @PostConstruct public void init() { System.out.println("Je passe dans le post Construct"); oeuvres = proxyOeuvreBusiness.getAllInfoOeuvres(); oeuvres = proxyOeuvreBusiness.getAllInfoOeuvres(); System.out.println("Je suis passé dans le post Construct"); } /** * @return the oeuvres */ public List<Oeuvre> getOeuvres() { return oeuvres; } /** * @param oeuvres the oeuvres to set */ public void setOeuvres(List<Oeuvre> oeuvres) { this.oeuvres = oeuvres; } /** * @return the mediums */ public List<Medium> getMediums() { return mediums; } /** * @param mediums the mediums to set */ public void setMediums(List<Medium> mediums) { this.mediums = mediums; } }
mon Dao
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 package oeuvresBusiness; import java.util.List; import javax.ejb.EJB; import javax.ejb.Remote; import javax.ejb.Stateless; import fr.ov.JabDibbets.entities.Medium; import fr.ov.JabDibbets.entities.Oeuvre; import fr.ov.JanDibbets.idao.OeuvreIDao; import oeuvresIBusiness.OeuvresIBusiness; @Remote (OeuvresIBusiness.class) @Stateless public class oeuvresBusiness implements OeuvresIBusiness { @EJB private OeuvreIDao proxyOeuvreDao; @Override public List<Oeuvre> getAllInfoOeuvres() { List<Oeuvre> oeuvres = null; oeuvres = proxyOeuvreDao.getAllInfoOeuvres(); //oeuvres = proxyOeuvreDao.findAll(); System.out.println("Dans le Business, la taille de la liste est de : " + oeuvres.size()); return oeuvres; } }
et enfin mon entité, ça peut peut être aider à comprendre...
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 package fr.ov.JanDibbets.dao; import java.util.ArrayList; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import fr.ov.JabDibbets.entities.Medium; import fr.ov.JabDibbets.entities.Oeuvre; import fr.ov.JanDibbets.idao.OeuvreIDao; @Remote(OeuvreIDao.class) @Stateless public class OeuvreDao extends GenericDao<Oeuvre> implements OeuvreIDao { @PersistenceContext (unitName = "JanDibbetsPU") private EntityManager em; static final String AllInfosOeuvres="SELECT * FROM oeuvre"; private final String reqJPA="SELECT o FROM Oeuvre o"; private final String reqJPA2="SELECT o.name, o.year FROM Oeuvre o"; @Override @SuppressWarnings("unchecked") public List<Oeuvre> getAllInfoOeuvres() { List<Oeuvre> oeuvres = null; Query requete = em.createQuery(reqJPA2); oeuvres= requete.getResultList(); System.out.println("La taille de la liste est de : " + oeuvres.size()); return oeuvres; } }
Si quelqu'un peut m'aiguiller, cela fait des heures que je bloque et cherche une solution.
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284 package fr.ov.JabDibbets.entities; import java.io.Serializable; import java.text.Format; import java.time.Year; import java.util.Date; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @Entity @Table(name = "oeuvre") public class Oeuvre implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Integer id; @Column(name = "name") private String name; @Temporal(value = TemporalType.DATE) @Column(name = "year") private Date year; @Column(name = "width") private String width; @Column(name = "height") private String height; @Column(name = "photo") private String photo; @Column(name = "id_catalogue_raisonne") private String idCatalogueRaisonne; @ManyToOne @JoinColumn(name="proprietaire_id", referencedColumnName = "id") private Proprietaire proprietaire; @ManyToOne @JoinColumn(name = "medium_id", referencedColumnName = "id") private Medium medium; @ManyToOne @JoinColumn(name = "unite_id", referencedColumnName = "id") private Unite unite; @OneToMany(mappedBy = "oeuvre", cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) private List<Presentation> presentations; public Oeuvre() { super(); } public Oeuvre(Integer id, String name, Date year, String width, String height, String photo, String idCatalogueRaisonne, Proprietaire proprietaire, Medium medium, Unite unite, List<Presentation> presentations) { super(); this.id = id; this.name = name; this.year = year; this.width = width; this.height = height; this.photo = photo; this.idCatalogueRaisonne = idCatalogueRaisonne; this.proprietaire = proprietaire; this.medium = medium; this.unite = unite; this.presentations = presentations; } /** * @return the id */ public Integer getId() { return id; } /** * @param id the id to set */ public void setId(Integer id) { this.id = id; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the year */ public Date getYear() { return year; } /** * @param year the year to set */ public void setYear(Date year) { this.year = year; } /** * @return the width */ public String getWidth() { return width; } /** * @param width the width to set */ public void setWidth(String width) { this.width = width; } /** * @return the height */ public String getHeight() { return height; } /** * @param height the height to set */ public void setHeight(String height) { this.height = height; } /** * @return the photo */ public String getPhoto() { return photo; } /** * @param photo the photo to set */ public void setPhoto(String photo) { this.photo = photo; } /** * @return the idCatalogueRaisonne */ public String getIdCatalogueRaisonne() { return idCatalogueRaisonne; } /** * @param idCatalogueRaisonne the idCatalogueRaisonne to set */ public void setIdCatalogueRaisonne(String idCatalogueRaisonne) { this.idCatalogueRaisonne = idCatalogueRaisonne; } /** * @return the proprietaire */ public Proprietaire getProprietaire() { return proprietaire; } /** * @param proprietaire the proprietaire to set */ public void setProprietaire(Proprietaire proprietaire) { this.proprietaire = proprietaire; } /** * @return the medium */ public Medium getMedium() { return medium; } /** * @param medium the medium to set */ public void setMedium(Medium medium) { this.medium = medium; } /** * @return the unite */ public Unite getUnite() { return unite; } /** * @param unite the unite to set */ public void setUnite(Unite unite) { this.unite = unite; } /** * @return the presentations */ public List<Presentation> getPresentations() { return presentations; } /** * @param presentations the presentations to set */ public void setPresentations(List<Presentation> presentations) { this.presentations = presentations; } @Override public String toString() { return "Oeuvre [id=" + id + ", name=" + name + ", year=" + year + ", width=" + width + ", height=" + height + ", photo=" + photo + ", idCatalogueRaisonne=" + idCatalogueRaisonne + ", proprietaire=" + proprietaire + ", medium=" + medium + ", unite=" + unite + ", presentations=" + presentations + "]"; } }
Si quelqu'un, au passage, sait aussi comment spécifier qu'en base, on ne veut que des années, ce serait super!
Merci d'avance, et bonne soirée!
Un débutant Java
Partager