bonjour,
Je suis débutante en développement web à base de java EE, je construits la portail intranet en utilisant les technologies JSF2, JPA2, EJB3, glassfish, Eclipse Kepler, Maven2, PostGrSQL 9.1, et eclipseLink comme provider de la couche JPA2, en fait j'essaye d'afficher la liste des formations de la base de donnée sur le navigateur et les propriétés de chaque formation, mais on m'affiche l'@ phisique de la ligne au lieu de sa valeur:
la page xhtml :
le code du 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 <!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:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <head> </head> <body> <h:outputText value="#{formationBean.allformation}"></h:outputText> </body> </html>
le code du DAO de l'entité
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 package mbeans; import java.util.Date; import java.util.List; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.bean.SessionScoped; import daoImpl.FormationDAOImpl; import entities.Formation; @ManagedBean @SessionScoped public class FormationBean { private FormationDAOImpl formationDao; public FormationBean() { formationDao=new FormationDAOImpl(); } public List<Formation> getAllformation(){ return formationDao.getAllFormation(); } public FormationDAOImpl getFormationDao() { return formationDao; } public void setFormationDao(FormationDAOImpl formationDao) { this.formationDao = formationDao; }
la classe entité :
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 package daoImpl; import java.util.Date; import java.util.List; import javax.ejb.Local; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.persistence.Query; import dao.FormationDAO; import entities.Formation; public class FormationDAOImpl { private static EntityManager em; private static EntityManagerFactory factory; public FormationDAOImpl() { if(factory==null) factory=Persistence.createEntityManagerFactory("mavenTest"); if(em==null) em=factory.createEntityManager(); } public Formation getFormationById(long id) { return null; } public List<Formation> getAllFormation() { List<Formation> listeFormation; Query q; em.getTransaction().begin(); q=em.createQuery("select f from Formation f ORDER BY f.titre"); listeFormation = q.getResultList(); em.getTransaction().commit(); return listeFormation; }
le ficher persistence.xml :
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 package mbeans; import java.util.Date; import java.util.List; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.bean.SessionScoped; import daoImpl.FormationDAOImpl; import entities.Formation; @ManagedBean @SessionScoped public class FormationBean { private FormationDAOImpl formationDao; /*private Integer id; private String titre; private String description; private Integer duree; private Date dateDebut; private Date dateFin;*/ public FormationBean() { formationDao=new FormationDAOImpl(); } public List<Formation> getAllformation(){ return formationDao.getAllFormation(); } /*public String createformation(){ formationDao.createFormation(id, titre, description, duree, dateDebut, dateFin); id=null; titre=""; description=""; duree=null; dateDebut=null; dateFin=null; return null;*/ public FormationDAOImpl getFormationDao() { return formationDao; } public void setFormationDao(FormationDAOImpl formationDao) { this.formationDao = formationDao; }
le fichier faces-config.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="mavenTest" transaction-type="RESOURCE_LOCAL"> <class>entities.Formation</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5433/postgres"/> <property name="javax.persistence.jdbc.user" value="postgres"/> <property name="javax.persistence.jdbc.password" value="admin"/> <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/> </properties> </persistence-unit> </persistence>
et mon pom.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?xml version="1.0" encoding="UTF-8"?> <faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" version="2.2"> <managed-bean> <managed-bean-name>formationBean</managed-bean-name> <managed-bean-class>mbeans.FormationBean</managed-bean-class> <managed-bean-scope>application</managed-bean-scope> </managed-bean> </faces-config>
merci d'avance
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 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>maven.test</groupId> <artifactId>mavenTest</artifactId> <version>0.0.1-SNAPSHOT</version> <repositories> <repository> <id>oss.sonatype.org</id> <name>OSS Sonatype Staging</name> <url>https://oss.sonatype.org/content/groups/staging</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.5.0-RC1</version> <exclusions> <exclusion> <groupId>org.eclipse.persistence</groupId> <artifactId>commonj.sdo</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.1.11</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.1.11</version> </dependency> <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901.jdbc4</version> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency> </dependencies> </project>
Partager