when I try to render the view, browser show this error
01:46:11,371 GRAVE [javax.enterprise.resource.webcontainer.jsf.application] (http--127.0.0.1-8080-1) Error Rendering View[/index.xhtml]: javax.el.PropertyNotFoundException: /index.xhtml @15,74 value="#{actividades.getAll}": The class 'org.pfc.controller.principal.ActividadesController' does not have the property 'getAll'.
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
ActvidadController code
@ManagedBean(name="actividades")
@ViewScoped public class ActividadesController implements Serializable {
private static final long serialVersionUID = 1L;
private final static Log logger=LogFactory.getLog(ActividadesController.class);
@ManagedProperty(value="#{actividadBO}")
private ActividadBO actividad;
public void setActividad(ActividadBO actividad) {
this.actividad = actividad;
}
public List<Actividad> getAll(){
logger.trace("ActividadesController.getAll");
return actividad.getAll();
}
}
View code
<h:body>
<ui:composition template="/WEB-INF/templates/main-template.xhtml">
<ui:define name="content">
<h:dataTable value="#{actividades.getAll}" var="actividad">
<h:column>
<f:facet name="header">
<h:outputText>Título</h:outputText>
</f:facet>
<h:outputText value="{actividad.titulo}"></h:outputText>
</h:column>
</h:dataTable>
</ui:define>
</ui:composition>
</h:body>
I use JBOSS 7 and my project has el-impl2.2.jar,el-api.1.1.jar and icefaces3 libraries.
I don´t understand why the render not working.
Any suggestions?
Kind regards.
Here,
<h:dataTable value="#{actividades.getAll}" var="actividad">
Your EL expression is invalid. It's looking for a method getGetAll()
, but you only have a getAll()
method representing a getter for the (fictive) property all
. The property doesn't need to exist at all (it's supposed to be private
anyway).
So, to fix your problem, it must be
<h:dataTable value="#{actividades.all}" var="actividad">
or, if you're using EL 2.2 (but this way is not recommended)
<h:dataTable value="#{actividades.getAll()}" var="actividad">
Either way, it will call the proper getAll()
method.
Unrelated to the concrete problem, you've by the way another design flaw in your code. A getter is invoked as many times as EL needs to resolve it. Doing business/database access job inside a getter method is a bad idea. A getter is supposed to just return bean properties. Rather move the DB job out to bean's (post)constructor.
private List<Actividad> all;
@PostConstruct
public void init() {
all = actividad.getAll();
}
public List<Actividad> getAll(){
logger.trace("ActividadesController.getAll");
return all;
}