本文介绍了p:commandButton 操作抛出 javax.el.PropertyNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误在于:

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

它看起来好像没有找到validar方法.它认为它是一个属性.

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

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


}

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

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

推荐答案

如果您没有正确安装 PrimeFaces,就会发生这种情况.这样,所有 <p:xxx> 标签都被视为模板文本(也就是说,它们不会被 Facelets 解析为 JSF 组件,而是直接打印到 HTML 输出的普通原版).模板文本中的所有 EL 表达式默认解析为属性值表达式(如 <p>blah #{bean.foo} blah</p>),它需要一个 getter 方法.所有最初表示方法表达式的 EL 表达式都将抛出这个异常,因为在 bean 中找不到 getter.

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.

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

To properly install PrimeFaces, make sure that the JAR file is in webapp's /WEB-INF/lib (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!), and 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.

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

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, then you can also face exactly this problem. You'd need to either upgrade PrimeFaces to at least 3.0, or to fall back to using 2.x compatible taglib URI http://primefaces.prime.com.tr/ui.

这篇关于p:commandButton 操作抛出 javax.el.PropertyNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 03:36