I am currently trying to write an application using JSF that uses an EJB session bean to call a database (MySQL), but when I try to access the page, I get an error that says
The class 'model.PlanetQueryManagedBean$Proxy$_$$_WeldClientProxy' does not have the property 'getPlanets'.
The code for the JSF page is as follows:
<?xml version='1.0' encoding='UTF-8' ?>
<!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">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:dataTable value="#{planetQueryManagedBean.getThePlanets}" var="pln">
<h:column>
<f:facet name="header">Name</f:facet>
#{pln.name}
</h:column>
<h:column>
<f:facet name="header">Description</f:facet>
#{pln.desc}
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
The code for JSF managed bean is:
package model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Named;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
@Named
@SessionScoped
public class PlanetQueryManagedBean implements Serializable {
@EJB
private QueryBean thePlanets;
public List<Planets> getThePlanets() {
return thePlanets.getListofPlanets();
}
}
And lastly, the EJB Session bean:
package model;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
@Stateless
public class QueryBean {
@PersistenceContext(name="PlanetsORM")
EntityManager em;
public QueryBean() {
}
public List<Planets> getListofPlanets() {
TypedQuery<Planets> theQuery = em.createQuery("select p from Planets p", Planets.class);
List<Planets> result = theQuery.getResultList();
return result;
}
}
I have looked in the book Core JavaServer Faces as main source and as I understand it, this is what should be done. I have also, of course, looked closely at the Stack Overflow questions, but I have not found anything to help me.
I have found a mentioning that something like this could happen if the EJB was not successfully instantiated, but I don't really know how to find that out...
I am using GlassFish 4.0 as application server and Eclipse as my IDE.
Could anyone help me? Or at least help me to find out how to understand the error better?
Best regards,
Tobias