Search code examples
jsfprimefacespropertynotfoundexceptionmethodexpression

p:commandButton action throws javax.el.PropertyNotFoundException


The error is in:

javax.el.PropertyNotFoundException: /index.xhtml: Property 'validar' not found on type fya.beanpages.IndexBean

Its looks like it doesnt find the validar method. And it thinks it is an attribute.

This is the xhtml:

<!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:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">

<h:head>  
  <title>FYA WEB</title>
</h:head>  

<h:body>  
    <ui:composition template="/base/base.xhtml">
    <ui:param name="title" value="FYA Web Login"/>
        <ui:define name="content">
            <h:form id="form">  
                <p:panel id="panel" header="Inicio Sesión">  
                    <p:messages id="panelmsg"/>  

                    <h:panelGrid columns="3">  
                        <h:outputLabel for="nomUsuario" value="Usuario: *" />  
                        <p:inputText id="nomUsuario" value="#{login.usu.nomusuario}" required="true" label="Usuario"/>

                        <h:outputLabel for="pwdUsuario" value="Contraseña: *" />  
                        <p:password id="pwdUsuario" value="#{login.usu.contraseña}" label="Contraseña" required="true"/>  
                    </h:panelGrid>  

                    <p:commandButton id="btnIniciar" value="Iniciar Sesión" action="#{login.validar}" update="panelmsg" ajax="true"/>  
                </p:panel>  
            </h:form>
        </ui:define>
    </ui:composition>        
</h:body>

This is the managed Bean.

package pe.edu.cibertec.managed;
@ManagedBean(name="login")
public class LoginBean {

private Usuario usuario=new Usuario();
private static LoginService loginService= new LoginServiceImpl();

public Usuario getUsuario() {
    return usuario;
}

public void setUsuario(Usuario usuario) {
    this.usuario = usuario;
}

public String validar() throws Exception {
    if(loginService.validar(usuario))
        return "paginas/principal";
    else{
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Datos Incorrectos"));
        return null;
    }
}


}

Maybe i think im doing something wrong, can you help me please?


Solution

  • That can happen when you didn't properly install PrimeFaces. This way all <p:xxx> tags are treated as template text (meaning, they are not parsed as JSF components by Facelets but printed plain vanilla straight to HTML output). All EL expressions in template text are by default resolved as property value expressions (like as in <p>blah #{bean.foo} blah</p>) which requires a getter method. All EL expressions which initially represent a method expression would then throw exactly this exception because there's no getter found in the bean.

    To properly install PrimeFaces, make sure that the PrimeFaces JAR file ends up properly in webapp's /WEB-INF/lib. If you're using Maven as build tool, then this can be achieved by adding the following dependency:

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version><!-- Check https://mvnrepository.com/artifact/org.primefaces/primefaces for latest version --></version>
        <classifier>jakarta</classifier> <!-- if you're already using Faces 3.0 or newer instead of JSF 2.x or older -->
    </dependency>
    

    You can find the latest available version in Maven repository list. The jakarta classifier tag should be added if you're already using Faces 3.0 or newer with jakarta.* imports instead of JSF 2.x or older with javax.* imports.

    If you're using any IDE like Eclipse, make sure that you absolutely do not touch Build Path setting, if you ever fiddled there in a careless attempt to solve it, undo it all! Also make sure that the project is properly rebuilt and that the server's work folder is properly cleant up and that the deploy in the server does contain the PrimeFaces JAR file in the right place.

    Another thing to take into account, the taglib URI http://primefaces.org/ui was introduced in PrimeFaces 3.0. So if you happen to have a JAR of PrimeFaces 2.x or older in the runtime classpath, then you can also face exactly this problem. You'd need to remove it or replace it by at least version 3.0.