IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

Problème d'affichage des valeurs des attributs d'une entité bean


Sujet :

JSF Java

  1. #1
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Mai 2012
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Mai 2012
    Messages : 20
    Points : 18
    Points
    18
    Par défaut Problème d'affichage des valeurs des attributs d'une entité bean
    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:
    Nom : @entity.png
Affichages : 187
Taille : 18,2 Ko

    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
     
    <!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 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
     
    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;
    	}
    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
    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;
    	}
    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
    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 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
     
    <?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>
    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
    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>
    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
    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>
    merci d'avance
    Images attachées Images attachées  

  2. #2
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Mai 2012
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Mai 2012
    Messages : 20
    Points : 18
    Points
    18
    Par défaut manque d'une variable
    Salut,

    en fin j'ai compris l'erreur il faut déclarer une variable dans un élément dataTable et à chaque outputText il faut mettre l'attribut à afficher de l'entité
    c'est ça :

    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:h="http://java.sun.com/jsf/html"
    	xmlns:f="http://java.sun.com/jsf/core"
    	xmlns:p="http://primefaces.org/ui">
     
    <head>
    <title>liste des formations diponibles</title>
    </head>
    <body>
    <h3>Les formations disponibles pour les employés de l'offices des changes </h3>
    <h:dataTable border="1" value="#{formationBean.allformation}" var="for">
        <h:column id="c0">
           <p:facet name="header">
              <h:outputLabel value="ID de la formation"></h:outputLabel>
            </p:facet>
             <h:outputText value="#{for.id}"></h:outputText>
         </h:column>
         <h:column id="c1">
           <p:facet name="header">
              <h:outputLabel value="titre de la formation"></h:outputLabel>
            </p:facet>
            <h:outputText value="#{for.titre}"></h:outputText>
         </h:column>
         <h:column id="c2">
            <p:facet name="header">
              <h:outputLabel value="description"></h:outputLabel>
         </p:facet>
          <h:outputText value="#{for.description}"></h:outputText>
        </h:column>
    </h:dataTable>
     
    </body>
    </html>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 30/03/2011, 03h07
  2. Réponses: 14
    Dernier message: 20/11/2007, 18h28
  3. Réponses: 5
    Dernier message: 15/06/2007, 11h58
  4. [MySQL] problème avec la récupération des valeurs des variables POST
    Par Jasmine80 dans le forum PHP & Base de données
    Réponses: 20
    Dernier message: 11/05/2007, 16h08
  5. Affichage des valeurs des variables avec tkprof
    Par hkhan13 dans le forum Oracle
    Réponses: 2
    Dernier message: 04/07/2006, 11h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo