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 :

property not found <h:dataTable>


Sujet :

JSF Java

  1. #1
    Provisoirement toléré
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    188
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 188
    Points : 68
    Points
    68
    Par défaut property not found <h:dataTable>
    J'utilise JSF et JPA pour mon application.
    Le SA est JBOSS 4.0.
    Je veux afficher dans ma page jsf des données:


    Voici la structure de mon application:

    J'ai crée un Dao qui fait des requêtes jpql:

    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
     
    public  class CocktailDao implements IDao {
    	@PersistenceContext
    	//private EntityManager em;
    	   //stores a reference to global EMF for acquiring EM
        protected JPAResourceBean jpaResourceBean;
    	public JPAResourceBean getJpaResourceBean() {
    		return jpaResourceBean;
    	}
     
     
    	// obtenir tous les cocktails
    	public List<Cocktail> getAll() {		
    	    //Create an EntityManager from the Factory stored in the JPAResourceBean
    	    EntityManager em = jpaResourceBean.getEMF().createEntityManager();
     
    		return em.createQuery("select c from Cocktail c").getResultList();
    	}

    dans mon 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
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
       <managed-bean>
          <managed-bean-name>cocktailManagerBean</managed-bean-name>
          <managed-bean-class>bean.CocktailManagerBean</managed-bean-class>
          <managed-bean-scope>session</managed-bean-scope>
          <managed-property>
             <property-name>cocktailDao</property-name>
             <value>#{cocktailDao}</value>
          </managed-property>
       </managed-bean>
     
       <managed-bean>
          <managed-bean-name>jpaResourceBean</managed-bean-name>
          <managed-bean-class>bean.JPAResourceBean</managed-bean-class>
          <managed-bean-scope>application</managed-bean-scope>
       </managed-bean>
     
       <managed-bean>
          <managed-bean-name>cocktailDao</managed-bean-name>
          <managed-bean-class>dao.CocktailDao</managed-bean-class>
          <managed-bean-scope>session</managed-bean-scope>
          <managed-property>
             <property-name>jpaResourceBean</property-name>
             <value>#{jpaResourceBean}</value>
          </managed-property>
       </managed-bean>
    voici mon cocktailManagerBean:

    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
     
    public class CocktailManagerBean{
     
        // This caches the categories.  We can assume they are non-volatile and
        //can cache them in this session scoped bean.
        protected Cocktail[] cocktails;
     
        // This attribute holds a reference to the Inventory service that will provide
        // data access for the ui.
        protected CocktailDao cocktailDao;
     
        public CocktailManagerBean() {
        }
     
        public Cocktail[] getCocktails(){
            try{
                if (this.cocktails == null){
                    Collection<Cocktail> tempCollection = cocktailDao.getAll();
                    this.cocktails = tempCollection.toArray(new Cocktail[tempCollection.size()]);
                }
            }catch (RuntimeException ex){
                handleException(ex);
            }
            return this.cocktails;
        }
    J'ai bien défini mon jpaRessourceBean:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
     public class JPAResourceBean {
     
        protected EntityManagerFactory emf;
     
         public EntityManagerFactory getEMF (){
            if (emf == null){
                emf = Persistence.createEntityManagerFactory("jpa");
            }
            return emf;
        }
    }
    voici ma page jsp:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
         <f:view>
           <h:dataTable value="#{cocktailManagerBean.cocktails}"
                                var="menuItem" >
     
                         <h:outputText value="#{menuItem.nomCocktail}"/>
     
                   </h:dataTable>
        </f:view>


    Voici mon code error:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
    javax.faces.el.PropertyNotFoundException: Bean: dao.CocktailDao, property: jpaResourceBean
    Je ne comprends pas car j'ai bien défini cette propriété et son getter.
    Quelqu'un a une idée svp?
    Merci

  2. #2
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    tu as un getter pour jspRressources..?
    je te conseille de ne pas passer directement ce bean à la JSP, et passer par un bean valueObject.

  3. #3
    Provisoirement toléré
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    188
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 188
    Points : 68
    Points
    68
    Par défaut
    oui, j'ai bien défini un getter ( cf code que j'ai copié)

    je devrais utiliser autre chose que ce bean ci-dessous?

    <h:dataTable value="#{cocktailManagerBean.cocktails}"

    Merci

  4. #4
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    le mieux c'est de faire un objet qui prend que les valeurs dont tu as besoin du DAO, et tu l' l'utilise en JSF, comme ça il y'a une séparation entre JPA..DAO..et la page JSF.

  5. #5
    Provisoirement toléré
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    188
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 188
    Points : 68
    Points
    68
    Par défaut
    j'ai simplifié la chose mais cette fois-ci, je suis redirigé vers page error et je n'ai pas de message d'erreur.

    voici ma classe service où j'ai crée en dur une liste de cocktails au lieu de passer par la couche DAO.

    Tout se passe bien, à la sortie de la méthode, j'ai bien ma liste correcte en mode debug.

    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
     
    	public class CocktailService implements IService {
     
    //	private CocktailDao dao = new CocktailDao();
    	private static List<Cocktail> cocktailist;	
     
     
    	public List<Cocktail> getCocktailist() {
    			//cocktailist = dao.getAll();
    		if (cocktailist==null) {
    			cocktailist= new ArrayList<Cocktail>();
    			cocktailist.add(new Cocktail(new Integer("1"),"cocktailno2", "Versez le jus"));
    			cocktailist.add( new Cocktail(new Integer("2"),"cocktailno3", "Versez la sauce"));
    		}
     
     
    		return cocktailist;
     
    	}

    voici ma page jsp

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     <h:dataTable border="0" rules="all" value="#{cocktailService.cocktailist}"
    		var="cocktail">
    		// ça plante uniquement en mettant ce code.
    	</h:dataTable>
    voici ma classe Cocktail:

    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
     
    public class Cocktail {
     
     
    	private Integer id;
     
        private String nomCocktail="";
     
        private String recette="";
     
     
        public Cocktail() {
     
        }
     
           public Cocktail(Integer id,String nomCocktail, String recipe) {
            this.id=id;
            this.nomCocktail=nomCocktail;
            this.recette=recipe;
     
        }
     
    ...
      }
    et voici mon fichier de config:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     
       <managed-bean>
          <managed-bean-name>cocktailService</managed-bean-name>
          <managed-bean-class>service.CocktailService</managed-bean-class>
          <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>

  6. #6
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Points : 5 059
    Points
    5 059
    Par défaut
    et l'erreur ??

  7. #7
    Provisoirement toléré
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    188
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 188
    Points : 68
    Points
    68
    Par défaut
    Désolé, le problème est bien résolu, c'était mon fichier web.xml qui a été modifié
    et le welcome file n'était plus présent.

    Pour ma liste, il devait y avoir une petite erreur.

    Merci!

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

Discussions similaires

  1. Property not found on type
    Par barmic dans le forum JSF
    Réponses: 11
    Dernier message: 10/12/2010, 13h53
  2. [RCP] File.properties not found
    Par rahmoucha dans le forum Eclipse Platform
    Réponses: 2
    Dernier message: 03/06/2010, 16h35
  3. hibernate.properties not found
    Par bpmfouka dans le forum Hibernate
    Réponses: 2
    Dernier message: 08/02/2010, 12h35
  4. Resource MessageResources_fr_FR.properties Not Found.
    Par pigeon11 dans le forum Struts 1
    Réponses: 2
    Dernier message: 26/09/2007, 12h01
  5. [jsp] property not found??
    Par champion dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 03/01/2005, 17h56

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