JSF2 - javax.el.PropertyNotFoundException. Does not work with methods

when I try to display the view, the browser shows 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(); } } 

Code view

  <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 am using JBOSS 7 and my project has libraries el-impl2.2.jar, el-api.1.1.jar and icefaces3.

I do not understand why the render does not work.

Any suggestions?

Sincerely.

+4
source share
1 answer

Here

 <h:dataTable value="#{actividades.getAll}" var="actividad"> 

Your EL expression is not valid. It is looking for the getGetAll() method, but you only have the getAll() method representing the getter for the (dummy) all property. The property does not have to exist (it must be private anyway).

So, to fix your problem, it must be

 <h:dataTable value="#{actividades.all}" var="actividad"> 

or if you are using EL 2.2 (but this method is not recommended)

 <h:dataTable value="#{actividades.getAll()}" var="actividad"> 

In any case, he will choose the correct getAll() method.


Unrelated to a specific problem, you have, by the way, another design flaw in your code. A getter is called as many times as EL is required. Doing work with database / database access inside the getter method is a bad idea. The getter is supposed to simply return bean properties. Rather, move the database to the bean (post) constructor.

 private List<Actividad> all; @PostConstruct public void init() { all = actividad.getAll(); } public List<Actividad> getAll(){ logger.trace("ActividadesController.getAll"); return all; } 

See also:

+10
source

Source: https://habr.com/ru/post/1400313/


All Articles