【问题标题】:p:commandButton action throws javax.el.PropertyNotFoundExceptionp:commandButton 操作抛出 javax.el.PropertyNotFoundException
【发布时间】:2016-04-13 05:32:13
【问题描述】:

错误在:

javax.el.PropertyNotFoundException: /index.xhtml: 在类型 fya.beanpages.IndexBean 上找不到属性“validar”

它看起来好像没有找到验证方法。它认为它是一个属性。

这是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>

这是托管 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;
    }
}


}

也许我觉得我做错了什么,你能帮帮我吗?

【问题讨论】:

标签: jsf primefaces propertynotfoundexception methodexpression


【解决方案1】:

当您没有正确安装 PrimeFaces 时,可能会发生这种情况。这样,所有&lt;p:xxx&gt; 标签都被视为模板文本(这意味着它们不会被 Facelets 解析为 JSF 组件,而是直接打印到 HTML 输出中)。默认情况下,模板文本中的所有 EL 表达式都解析为属性值表达式(如&lt;p&gt;blah #{bean.foo} blah&lt;/p&gt;),这需要一个 getter 方法。所有最初表示方法表达式的 EL 表达式都会抛出这个异常,因为在 bean 中找不到 getter。

要正确安装 PrimeFaces,请确保 JAR 文件位于 webapp 的 /WEB-INF/lib 中(如果您使用的是 Eclipse 等任何 IDE,请确保绝对不要触摸 Build Path 设置,如果您曾经不小心尝试解决它,请全部撤消!),并确保项目已正确重建,服务器的工作文件夹已正确清理,并且服务器中的部署确实包含 PrimeFaces JAR文件放在正确的位置。

另外需要考虑的是,taglib URI http://primefaces.org/ui 是在 PrimeFaces 3.0 中引入的。因此,如果您碰巧有一个 PrimeFaces 2.x 或更早版本的 JAR,那么您也可能会遇到这个问题。您需要将 PrimeFaces 升级到至少 3.0,或者回退到使用 2.x 兼容的 taglib URI http://primefaces.prime.com.tr/ui

【讨论】:

  • 非常感谢,我正在配置构建路径设置,而且我正在使用旧版本的 PrimeFaces。
猜你喜欢
  • 2015-09-25
  • 2013-01-17
  • 1970-01-01
  • 1970-01-01
  • 2013-09-28
  • 2014-09-17
  • 1970-01-01
相关资源
最近更新 更多