當從EL調用JSF Bean時,我有一個關於方法簽名的問題。在JSF 2.0中調用方法的方法簽名?
在下面的例子中,我有3個方法調用,在的outputText value
屬性,並在該命令按鈕的actionListener
& & action
屬性。
<p:dataTable id="gridRPBDetails"
var="rpbDetail"
value="#{tInputBean.detailList}"
selection="#{tInputBean.selectedDetails}">
....
<p:column selectionMode="multiple" />
<p:column>
<h:outputText value="#{tInputBean.isNewRecord(rpbDetail) ? 'New' : tInputBean.isEditRecord(rpbDetail) ? 'Edited' : '-'}"/>
</p:column>
<p:column>
<p:commandButton
process="@this"
actionListener="#{tInputBean.activateDetail(rpbDetail)}"
action="#{tInputBean.querySubAnggaranListImpl(rpbDetail.map['subBudget.budget'])}"
update="DetailDialogForm"
oncomplete="detailDialog.show();"
image="ui-icon ui-icon-search"/>
</p:column>
....
一個很奇怪的是,無論是actionListener="#{tInputBean.activateDetail(rpbDetail)}"
和action="#{tInputBean.querySubAnggaranListImpl(rpbDetail.map['subBudget.budget'])}"
可以有一個自定義類型作爲參數(在這種情況下,這是一個my.package.Dto型):
public void activateDetail(Dto activeDetail) {
....
}
public void querySubAnggaranListImpl(Dto budget) {
DebugUtil.start("querySubAnggaranListImpl");
....
DebugUtil.end("querySubAnggaranListImpl");
}
其中isNewRecord方法需要一個java.lang.Object中:
public boolean isNewRecord(Dto record) { // this does NOT work
....
}
這是生成的跟蹤S:
ERROR BusinessExceptionHandler - javax.el.ELException: /TInput.xhtml @156,130 value="#{tInputBean.isNewRecord(rpbDetail) ? 'New' : tInputBean.isEditRecord(rpbDetail) ? 'Edited' : '-'}": java.lang.NoSuchMethodException: id.co.sofcograha.cashbank.webapp.paymentplan.TInputBean.isNewRecord(java.lang.Object)
javax.el.ELException: /TInput.xhtml @156,130 value="#{tInputBean.isNewRecord(rpbDetail) ? 'New' : tInputBean.isEditRecord(rpbDetail) ? 'Edited' : '-'}": java.lang.NoSuchMethodException: id.co.sofcograha.cashbank.webapp.paymentplan.TInputBean.isNewRecord(java.lang.Object)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:193)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:181)
at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:883)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularCell(DataTableRenderer.java:571)
at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:531)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:472)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:201)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:180)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:85)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:883)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:229)
at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:152)
at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:75)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:883)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoSuchMethodException: id.co.sofcograha.cashbank.webapp.paymentplan.TInputBean.isNewRecord(java.lang.Object)
at java.lang.Class.getMethod(Class.java:1605)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:405)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
at org.apache.el.parser.AstValue.getValue(AstValue.java:159)
at org.apache.el.parser.AstChoice.getValue(AstChoice.java:45)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 52 more
DEBUG DebugUtil - ************ END printing stack trace ************
但是,如果我加入這個方法,一切工作順利:
public boolean isNewRecord(Object o) { // this DOES work
return isNewRecord((Dto) o);
}
的基本問題是: 爲什麼該方法從JSF調用有時可以接受定製類型,有時不是?
順便說一句,即時通訊使用的是Tomcat 7,而這些是我的依賴關係:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
謝謝!
確實升級tomcat解決了問題。謝謝 ! – bertie 2011-07-05 07:08:06