当从EL调用JSF Bean时,我对JSF Bean中的方法签名有疑问。
在下面的示例中,我在outputText value
属性和actionListener
&&命令Button的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
....
}
这是生成的痕迹:
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>
谢谢!
答案 0 :(得分:1)
这是针对EL实现的。根据我在一个演示文稿中听到的内容,规范并不完全清楚这种情况,因此实现者必须做出决定。
但是Tomcat的实现应该如你所愿。尝试将tomcat升级到最新版本,并确保WEB-INF/lib