p:commandButton操作抛出javax.el.PropertyNotFoundException [英] p:commandButton action throws javax.el.PropertyNotFoundException

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

问题描述

错误在于:

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

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.

这是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表达式都被解析为需要使用getter方法的属性值表达式(例如<p>blah #{bean.foo} blah</p>中的表达式).所有最初表示方法表达式的EL表达式都将恰好引发此异常,因为在Bean中找不到吸气剂.

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中引入了标签库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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆