简体   繁体   English

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

[英]javax.el.ELException: Could not find property actionMethod in class com.example.Bean

While deploying GAE + primefaces application, I got following error:在部署 GAE + primefaces 应用程序时,出现以下错误:

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)

Even saveEmployee is already in EmployeeRepositoryImpl class.甚至saveEmployee已经在EmployeeRepositoryImpl类中。 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.ELException: Could not find property doSomething in class com.example.Bean javax.el.E​​LException:在类 com.example.Bean 中找不到属性 doSomething

This exception is literally trying to tell you that the Bean class doesn't have the following method:这个异常实际上是想告诉你Bean类没有以下方法:

public SomeObject getDoSomething() {
    return someObject;
}

(where SomeObject is the type of the doSomething property) (其中SomeObjectdoSomething属性的类型)

There are several causes for this.这有几个原因。

Action method expression is incorrectly interpreted as property value expression动作方法表达式被错误地解释为属性值表达式

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.鉴于属性名称在您的情况下实际上是动词和名词的组合,一个合理的原因是您错误地将操作方法​​绑定到某个实际上采用值表达式而不是方法表达式的 JSF 组件的属性。 Eg when you accidentally do例如,当你不小心做

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

or even甚至

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

instead of代替

<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";
}

(which can also be declared to return void by the way) (顺便也可以声明为返回void

Component is not resolved at all组件根本没有解决

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).换句话说,当您删除action属性然后尝试在浏览器中打开 JSF 页面时,它现在可以正常加载,但是您将在生成的 HTML 输出中看到未解析的整个组件(您可以通过右键单击查看浏览器中的)。

This can have several causes:这可能有多种原因:

  1. The XML namespace of the component is wrong or missing.组件的 XML 命名空间错误或缺失。 Eg in case of PrimeFaces you accidentally used the old PrimeFaces 2.x URI while you're actually using PrimeFaces 3+.例如,在 PrimeFaces 的情况下,您在实际使用 PrimeFaces 3+ 时不小心使用了旧的 PrimeFaces 2.x URI。

     <html ... xmlns:p="http://primefaces.prime.com.tr/ui">
  2. The XML namespace URI contains a typo. XML 命名空间 URI 包含一个错字。

     <html ... xmlns:p="http://primefaecs.org/ui">
  3. The XML namespace prefix does not match. XML 命名空间前缀不匹配。

     <html ... xmlns:pf="http://primefaces.org/ui">
  4. The XML namespace is totally missing. XML 命名空间完全缺失。

     <html ...>
  5. 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.换句话说,webapp 的/WEB-INF/lib文件夹中缺少包含组件库标签定义的 JAR。

Either way, all <p:xxx> tag won't be parsed and be considered as template text.无论哪种方式,所有<p:xxx>标签都不会被解析并被视为模板文本。 But, all EL expressions will still be evaluated (as if you're using <p>#{bean.text}</p> ), and they will all behave as ValueExpression s instead of MethodExpression s.但是,仍然会评估所有 EL 表达式(就像您使用<p>#{bean.text}</p> ),并且它们都将表现为ValueExpression而不是MethodExpression

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".如果您在堆栈跟踪中看到com.sun.faces.facelets.compiler.AttributeInstruction ,则表示该组件被解释为“纯文本”。 Otherwise you would have seen eg org.primefaces.component.commandbutton.CommandButton in the specific case of <p:commandButton> .否则你会在<p:commandButton>的特定情况下看到例如org.primefaces.component.commandbutton.CommandButton

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 rowSelectListener =““#{bean.method}”引发javax.el.E​​LException:类&#39;com.example.Bean&#39;没有属性&#39;method&#39; - rowSelectListener=“#{bean.method}” throws javax.el.ELException: The class 'com.example.Bean' does not have the property 'method' @ManagedProperty引发javax.el.E​​LException:无法将类java.lang.String类型的bean转换为com.example.Bean类 - @ManagedProperty throws javax.el.ELException: Cannot convert bean of type class java.lang.String to class com.example.Bean javax.el.E​​LException: 在 com.example.Bean 类型上读取“foo”时出错 - javax.el.ELException: Error reading 'foo' on type com.example.Bean javax.el.PropertyNotWritableException:类“com.example.Bean”没有可写属性“foo” - javax.el.PropertyNotWritableException: The class 'com.example.Bean' does not have a writable property 'foo' 找不到属性的javax.el.E​​LException - javax.el.ELException for property not found Tomcat 7找不到我的类抛出javax.el.E​​LException:java.lang.NoClassDefFoundError - Tomcat 7 can't find my class throws javax.el.ELException: java.lang.NoClassDefFoundError javax.el.E​​LException:不是有效的方法表达式 - javax.el.ELException: Not a Valid Method Expression 找不到javax.el.E​​LException方法 - javax.el.ELException Method not found javax.el.E​​LException:无法解析表达式[{pz:instanceof(object,&#39;com.project.domain.MyClass&#39;)}] - javax.el.ELException: Failed to parse the expression [{pz:instanceof(object,'com.project.domain.MyClass')}] javax.el.E​​LException:当将操作属性与方法和字符串一起使用时,不是有效的方法表达式 - javax.el.ELException: Not a Valid Method Expression when use action property with method and string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM