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:
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:
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:
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:
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:
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:
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