我目前正在尝试构建复合组件,这就是我利用组件的方式:
包括它与xmlns:albert="http://java.sun.com/jsf/composite/albert"
这是用法示例
<albert:infoButton
infoId="infoSingleRecord"
params="transDateFrom transDateTo"
mappingMethod="#{tBrowseBean_ConfirmedRPB.mapSendInfoSingleRecord}" />
这是放在resources / albert / infoButton.xhtml中的组件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="infoId" required="true" />
<composite:attribute name="params" />
<composite:attribute name="mappingMethod" method-signature="java.lang.String action()" />
</composite:interface>
<composite:implementation>
<p:commandButton
process="@this #{cc.attrs.params}"
actionListener="#{cc.attrs.mappingMethod}"
update="#{cc.attrs.infoId}Panel"
oncomplete="#{cc.attrs.infoId}Dialog.show()"
image="ui-icon ui-icon-search" />
</composite:implementation>
</html>
但是运行它时,单击infoButton时,此异常跟踪显示在我的catalina.out日志文件中:
Apr 25, 2011 10:08:43 AM javax.faces.event.MethodExpressionActionListener processAction
SEVERE: Received 'javax.el.PropertyNotFoundException' when invoking action listener '#{cc.attrs.mappingMethod}' for component 'j_idt71'
Apr 25, 2011 10:08:43 AM javax.faces.event.MethodExpressionActionListener processAction
SEVERE: javax.el.PropertyNotFoundException: /TBrowse_tabConfirmedRPB.xhtml @33,77 mappingMethod="#{tBrowseBean_ConfirmedRPB.mapSendInfoSingleRecord}": Property 'mapSendInfoSingleRecord' not found on type mywebapp.paymentplan.TBrowseBean_ConfirmedRPB
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at com.sun.faces.facelets.el.ContextualCompositeMethodExpression.invoke(ContextualCompositeMethodExpression.java:184)
at com.sun.faces.facelets.tag.TagAttributeImpl$AttributeLookupMethodExpression.invoke(TagAttributeImpl.java:450)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:777)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
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.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)
ERROR BusinessExceptionHandler - BusinessExceptioHandler handles an unhandled exception:
javax.faces.event.AbortProcessingException: /TBrowse_tabConfirmedRPB.xhtml @33,77 mappingMethod="#{tBrowseBean_ConfirmedRPB.mapSendInfoSingleRecord}": Property 'mapSendInfoSingleRecord' not found on type mywebapp.paymentplan.TBrowseBean_ConfirmedRPB
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:777)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
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.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: javax.el.PropertyNotFoundException: /TBrowse_tabConfirmedRPB.xhtml @33,77 mappingMethod="#{tBrowseBean_ConfirmedRPB.mapSendInfoSingleRecord}": Property 'mapSendInfoSingleRecord' not found on type mywebapp.paymentplan.TBrowseBean_ConfirmedRPB
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at com.sun.faces.facelets.el.ContextualCompositeMethodExpression.invoke(ContextualCompositeMethodExpression.java:184)
at com.sun.faces.facelets.tag.TagAttributeImpl$AttributeLookupMethodExpression.invoke(TagAttributeImpl.java:450)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
... 24 more
我不知道为什么会这样,因为在mywebapp.paymentplan.TBrowseBean_ConfirmedRPB,我已经提供了:
public String mapSendInfoSingleRecord(ActionEvent event) {
System.out.println("mapSendInfoSingleRecord");
return null;
}
然后,我尝试将虚拟的mapSendInfoSingleRecord字段放进去,看看会发生什么:
private String mapSendInfoSingleRecord;
public String getMapSendInfoSingleRecord() {
return mapSendInfoSingleRecord;
}
public void setMapSendInfoSingleRecord(String mapSendInfoSingleRecord) {
this.mapSendInfoSingleRecord = mapSendInfoSingleRecord;
}
但是单击按钮现在会产生以下异常:
Apr 25, 2011 10:32:46 AM javax.faces.event.MethodExpressionActionListener processAction
SEVERE: Received 'javax.el.MethodNotFoundException' when invoking action listener '#{cc.attrs.mappingMethod}' for component 'j_idt71'
Apr 25, 2011 10:32:46 AM javax.faces.event.MethodExpressionActionListener processAction
SEVERE: javax.el.MethodNotFoundException: Method not found: com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap@12f3802.mappingMethod()
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:225)
at org.apache.el.parser.AstValue.invoke(AstValue.java:253)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:777)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
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.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)
ERROR BusinessExceptionHandler - BusinessExceptioHandler handles an unhandled exception:
javax.faces.event.AbortProcessingException: Method not found: com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap@12f3802.mappingMethod()
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:777)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
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.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: javax.el.MethodNotFoundException: Method not found: com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap@12f3802.mappingMethod()
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:225)
at org.apache.el.parser.AstValue.invoke(AstValue.java:253)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
... 24 more
我已经针对mojarra 2.0.4-b09和2.1.1-b04版本进行了测试,结果相同。
我想知道我在这里做错了什么吗?
最佳答案
有两个问题:
首先,您定义的复合method-signature
<composite:attribute name="mappingMethod" method-signature="java.lang.String action()" />
与真实的方法签名不匹配
public String mapSendInfoSingleRecord(ActionEvent event)
其次,
actionListener
方法应返回void
而不是String
。我假设您只想要
action
方法,然后应该更改实际方法签名以摆脱ActionEvent
参数:public String mapSendInfoSingleRecord()
至于
actionListener
和action
,您可能会发现以下问题/答案很有用:Differences between action and actionListener。关于jsf - javax.el.PropertyNotFoundException与CompositeComponent吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5774968/