[英]rowSelectListener=“#{bean.method}” throws javax.el.ELException: The class 'com.example.Bean' does not have the property 'method'
[英]javax.el.ELException: Could not find property actionMethod in class com.example.Bean
在部署 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)
甚至saveEmployee
已經在EmployeeRepositoryImpl
類中。 這是怎么引起的,我該如何解決? 是否有任何我必須額外添加的注釋?
讓我們以通用格式重新表述異常,以便更好地理解原因:
javax.el.ELException:在類 com.example.Bean 中找不到屬性 doSomething
這個異常實際上是想告訴你Bean
類沒有以下方法:
public SomeObject getDoSomething() {
return someObject;
}
(其中SomeObject
是doSomething
屬性的類型)
這有幾個原因。
鑒於屬性名稱在您的情況下實際上是動詞和名詞的組合,一個合理的原因是您錯誤地將操作方法綁定到某個實際上采用值表達式而不是方法表達式的 JSF 組件的屬性。 例如,當你不小心做
<h:commandButton value="#{bean.doSomething}">Save</h:commandButton>
甚至
<h:button value="Save" outcome="#{bean.doSomething}" />
代替
<h:commandButton value="Save" action="#{bean.doSomething}" />
后者然后會期望以下方法,您可能實際上擁有:
public String doSomething() {
// ...
return "nextpage";
}
(順便也可以聲明為返回void
)
另一個可能的原因是該組件根本沒有被解釋為真正的組件,而是作為“純文本”。 換句話說,當您刪除action
屬性然后嘗試在瀏覽器中打開 JSF 頁面時,它現在可以正常加載,但是您將在生成的 HTML 輸出中看到未解析的整個組件(您可以通過右鍵單擊查看瀏覽器中的源)。
這可能有多種原因:
組件的 XML 命名空間錯誤或缺失。 例如,在 PrimeFaces 的情況下,您在實際使用 PrimeFaces 3+ 時不小心使用了舊的 PrimeFaces 2.x URI。
<html ... xmlns:p="http://primefaces.prime.com.tr/ui">
XML 命名空間 URI 包含一個錯字。
<html ... xmlns:p="http://primefaecs.org/ui">
XML 命名空間前綴不匹配。
<html ... xmlns:pf="http://primefaces.org/ui">
XML 命名空間完全缺失。
<html ...>
根本沒有安裝組件庫。 換句話說,webapp 的/WEB-INF/lib
文件夾中缺少包含組件庫標簽定義的 JAR。
無論哪種方式,所有<p:xxx>
標簽都不會被解析並被視為模板文本。 但是,仍然會評估所有 EL 表達式(就像您使用<p>#{bean.text}</p>
),並且它們都將表現為ValueExpression
而不是MethodExpression
。
識別根本原因的一種簡單方法是查看堆棧跟蹤。 如果您在堆棧跟蹤中看到com.sun.faces.facelets.compiler.AttributeInstruction
,則表示該組件被解釋為“純文本”。 否則你會在<p:commandButton>
的特定情況下看到例如org.primefaces.component.commandbutton.CommandButton
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.