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

查看:54
本文介绍了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)

有多种原因.

鉴于属性名称实际上是动词和名词的组合,因此,一个合理的原因是您将操作方法​​错误地绑定到某些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.

    无论哪种方式,都不会解析所有<p:xxx>标记并将其视为模板文本.但是,所有EL表达式仍将被求值(就像您正在使用<p>#{bean.text}</p>一样),它们的行为都将是ValueExpression s而不是MethodExpression s.

    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(在<p: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天全站免登陆