使用CompositeComponent的javax.el.PropertyNotFoundException?

ber*_*tie 2 jsf composite-component jsf-2 propertynotfoundexception

我目前正在尝试构建一个复合组件,这就是我如何使用我的组件:


包括它 xmlns:albert="http://java.sun.com/jsf/composite/albert"


这是用法示例

<albert:infoButton
    infoId="infoSingleRecord"
    params="transDateFrom transDateTo"
    mappingMethod="#{tBrowseBean_ConfirmedRPB.mapSendInfoSingleRecord}" />
Run Code Online (Sandbox Code Playgroud)

这是放在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>
Run Code Online (Sandbox Code Playgroud)

但运行它,当单击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
Run Code Online (Sandbox Code Playgroud)

我想知道为什么会这样,因为在mywebapp.paymentplan.TBrowseBean_ConfirmedRPB,我已经提供了这个:

public String mapSendInfoSingleRecord(ActionEvent event) {                                                                                                                             
    System.out.println("mapSendInfoSingleRecord");                                                                                                                                 
    return null;                                                                                                                                                                   
}
Run Code Online (Sandbox Code Playgroud)

之后,我尝试将虚拟mapSendInfoSingleRecord字段放入,看看会发生什么:

private String mapSendInfoSingleRecord;
public String getMapSendInfoSingleRecord() {
    return mapSendInfoSingleRecord;
}

public void setMapSendInfoSingleRecord(String mapSendInfoSingleRecord) {
    this.mapSendInfoSingleRecord = mapSendInfoSingleRecord;
}
Run Code Online (Sandbox Code Playgroud)

但是现在点击按钮会产生以下异常:

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
Run Code Online (Sandbox Code Playgroud)

我已经针对mojarra版本2.0.4-b09和2.1.1-b04进行了测试,结果相同.


我想知道我在这里做错了什么?

Bal*_*usC 6

有两个问题:

首先,method-signature你定义的复合材料

<composite:attribute name="mappingMethod" method-signature="java.lang.String action()" />
Run Code Online (Sandbox Code Playgroud)

与真实方法签名不匹配

public String mapSendInfoSingleRecord(ActionEvent event) 
Run Code Online (Sandbox Code Playgroud)

二,actionListener方法应该返回void不是String.

我假设你只是想要一个action方法,然后你应该改变真正的方法签名来摆脱这个ActionEvent论点:

public String mapSendInfoSingleRecord() 
Run Code Online (Sandbox Code Playgroud)

对于actionListenervs action,你可能会发现这个问题/答案很有用:action和actionListener之间的差异.

  • 哇酷 !修改后***方法签名= "java.lang.Void的动作(javax.faces.event.ActionEvent)"***匹配***无效mapSendInfoSingleRecord(ActionEvent的五)***,现在一切工程进展顺利.我选择了actionListener,因为我打算只在方法上做UI内容,而没有任何业务逻辑调用.为什么我返回的字符串,而这是一个ActionListener方法,是因为我与异常交易时测试各种方式,然后defnining void当越来越不确定,请尝试使用字符串遵循书中的基本的例子,而不是:-)谢谢大师! (2认同)