1

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

Denim Datta
  • 3,740
  • 3
  • 27
  • 53
  • 2
    The exception you got is from `javax.el` package (thus, related to EL expressions). This has hardly anything to do with EJBs. And, please, do not use Stack Overflow question editor as code editor. Right now the exception message and the code doesn't match each other (`getPlanets` != `getThePlanets`). Just copypaste real code unmodified, otherwise you're only introducing red herrings. By the way, you've another major problem in your managed bean code: [thou should not do business logic in a getter method](http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times/). – BalusC Nov 04 '13 at 11:14
  • what is the relationship between `PlanetQueryManagedBean` and `QueryBean`? How is `PlanetQueryManagedBean` invoked from a facelet? `PlanetQueryManagedBean` hides database connection particulars? – Thufir Sep 30 '14 at 09:48

1 Answers1

0

A property can have a setter and a getter. You have to reference the property without the get or set, and with the first letter in lowercase:

#{planetQueryManagedBean.thePlanets}
Pablo
  • 3,655
  • 2
  • 30
  • 44