javax.el.E​​LException:在类 com.example.Bean 中找不到属性 actionMethod [英] javax.el.ELException: Could not find property actionMethod in class com.example.Bean

查看:18
本文介绍了javax.el.E​​LException:在类 com.example.Bean 中找不到属性 actionMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在部署 GAE + primefaces 应用程序时,出现以下错误:

While deploying GAE + primefaces application, I got following error:

com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException: Error Rendering View[/CreateEmployee.xhtml]
javax.el.ELException: /CreateEmployee.xhtml: Could not find property saveEmployee in class com.fetchinglife.domain.data.dao.EmployeeRepositoryImpl
    at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:94)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)

甚至 saveEmployee 已经在 EmployeeRepositoryImpl 类中.这是怎么引起的,我该如何解决?是否有任何我必须额外添加的注释?

Even saveEmployee is already in EmployeeRepositoryImpl class. How is this caused and how can I solve it? Are there any annotations which I have to put extra?

推荐答案

让我们以通用格式重新表述异常,以便更好地理解原因:

Let's rephrase the exception in a general format in order to better understand the cause:

javax.el.E​​LException: 在类 com.example.Bean 中找不到属性 doSomething

javax.el.ELException: Could not find property doSomething in class com.example.Bean

这个异常实际上是想告诉你 Bean 类没有以下方法:

This exception is literally trying to tell you that the Bean class doesn't have the following method:

public SomeObject getDoSomething() {
    return someObject;
}

(其中SomeObjectdoSomething 属性的类型)

(where SomeObject is the type of the doSomething property)

造成这种情况的原因有多种.

There are several causes for this.

鉴于在您的情况下属性名称实际上是动词和名词的组合,一个合理的原因是您错误地将操作方法​​绑定到某些实际上采用值表达式而不是方法的 JSF 组件的属性表达.例如.当你不小心做

Given the fact that the property name is in your case actually a combination of a verb and noun, a resonable cause is you incorrectly bound an action method to an attribute of some JSF component which actually takes a value expression, not a method expression. E.g. when you accidentally do

<h:commandButton value="#{bean.doSomething}">Save</h:commandButton>

甚至

<h:button value="Save" outcome="#{bean.doSomething}" />

代替

<h:commandButton value="Save" action="#{bean.doSomething}" />

后者会期待以下方法,您可能实际上拥有:

The latter would then expect the following method, which you probably actually have:

public String doSomething() {
    // ...
    return "nextpage";
}

(顺便也可以声明返回void)

另一个可能的原因是该组件根本没有被解释为真正的组件,而是作为纯文本".换句话说,当您删除 action 属性,然后尝试在浏览器中打开 JSF 页面时,它现在可以正常加载,但是您将看到在生成的 HTML 输出中未解析的整个组件(您可以通过右键单击来查看,在浏览器中查看源代码).

Another probable cause is that the component is not interpreted as a real component at all, but as "plain text". In other words, when you remove the action attribute and then try to open the JSF page in browser, it'll now load fine, but you will see the whole component unparsed in the generated HTML output (which you can see via rightclick, View Source in browser).

这可能有多种原因:

  1. 组件的 XML 命名空间错误或缺失.例如.如果使用 PrimeFaces,您在实际使用 PrimeFaces 3+ 时不小心使用了旧的 PrimeFaces 2.x URI.

  1. The XML namespace of the component is wrong or missing. E.g. in case of PrimeFaces you accidentally used the old PrimeFaces 2.x URI while you're actually using PrimeFaces 3+.

 <html ... xmlns:p="http://primefaces.prime.com.tr/ui">

  • XML 命名空间 URI 包含拼写错误.

  • The XML namespace URI contains a typo.

     <html ... xmlns:p="http://primefaecs.org/ui">
    

  • XML 命名空间前缀不匹配.

  • The XML namespace prefix does not match.

     <html ... xmlns:pf="http://primefaces.org/ui">
    

  • 完全缺少 XML 命名空间.

  • The XML namespace is totally missing.

     <html ...>
    

  • 根本没有安装组件库.换句话说,webapp 的 /WEB-INF/lib 文件夹中缺少包含组件库标签定义的 JAR.

  • The component library is not installed at all. In other words, the JARs containing component library's tag definitions is missing in webapp's /WEB-INF/lib folder.

    无论哪种方式,所有 标签都不会被解析并被视为模板文本.但是,所有 EL 表达式仍将被评估(就像您使用 <p>#{bean.text}</p>),并且它们都将表现为 ValueExpressions 而不是 MethodExpressions.

    Either way, all <p:xxx> tag won't be parsed and be considered as template text. But, all EL expressions will still be evaluated (as if you're using <p>#{bean.text}</p>), and they will all behave as ValueExpressions instead of MethodExpressions.

    识别根本原因的一种简单方法是查看堆栈跟踪.如果您在堆栈跟踪中看到 com.sun.faces.facelets.compiler.AttributeInstruction,则表示该组件被解释为纯文本".否则你会看到例如org.primefaces.component.commandbutton.CommandButton的具体情况下.

    An easy way to recognize the root cause is looking at stack trace. If you're seeing com.sun.faces.facelets.compiler.AttributeInstruction in the stack trace, then it means that the component is interpreted as "plain text". Otherwise you would have seen e.g. org.primefaces.component.commandbutton.CommandButton in the specific case of <p:commandButton>.

    这篇关于javax.el.E​​LException:在类 com.example.Bean 中找不到属性 actionMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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