【问题标题】:Composite component with Error in JSFJSF 中出现错误的复合组件
【发布时间】:2015-01-31 22:06:19
【问题描述】:

好吧,我有下面的复合组件:

<composite:interface>
<composite:attribute name="acaoDestino" required="true"
        shortDescription="Método que será executado quando o usuário clicar no botão 'Sim'." />
</composite:interface>
<composite:implementation>
<h:commandButton actionListener="#{cc.attrs.acaoDestino}"
                        class="btn btn-primary" value="Sim">
                        <f:ajax render="@all" execute="@all" />
                    </h:commandButton>
</composite:implementation>

当我单击此命令按钮时,会调用两次 actionListener (acaoDestino)。在第一次调用中,该方法运行正常,但在第二次调用中出现错误:

Jan 31, 2015 7:00:32 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
Grave: javax.faces.FacesException: Unable to resolve composite component from using page using EL expression '#{cc.attrs.acaoDestino}'
    at com.sun.faces.facelets.tag.TagAttributeImpl$AttributeLookupMethodExpression.invoke(Unknown Source)
    at javax.faces.event.MethodExpressionActionListener.processAction(Unknown Source)
    at javax.faces.event.ActionEvent.processListener(Unknown Source)
    at javax.faces.component.UIComponentBase.broadcast(Unknown Source)
    at javax.faces.component.UICommand.broadcast(Unknown Source)
    at javax.faces.component.UIViewRoot.broadcastEvents(Unknown Source)
    at javax.faces.component.UIViewRoot.processApplication(Unknown Source)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(Unknown Source)
    at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
    at javax.faces.webapp.FacesServlet.service(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at br.com.jwebbuild.filter.LoginFilter.doFilter(LoginFilter.java:73)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    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:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    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:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

重要提示:我不希望这个 actionListener 被调用两次。另一个重要的注意事项是我正在绑定一个数据表,我不知道这是否会导致这个问题。

编辑 1

我的acaoDestino是ManagedBean中的一个方法,见:

public void removeSelected() {
...
}

直接在commandButton中使用会是这样的:

<h:commandButton actionListener="#{myManagedBean.removeSelected()}"
                        class="btn btn-primary" value="Sim">
                        <f:ajax render="@all" execute="@all" />
                    </h:commandButton>

编辑 2(我使用的是 JSF 2.2.9)

我编辑了我的属性 acaoDestino 放置方法签名

<composite:attribute name="acaoDestino" required="true" method-signature="void actionListener()"
        shortDescription="Método que será executado quando o usuário clicar no botão 'Sim'." />

现在我收到以下错误:

Advertência: java.lang.IllegalArgumentException: wrong number of arguments
javax.el.ELException: java.lang.IllegalArgumentException: wrong number of arguments

我在另一个复合组件中使用复合组件,看:

<jw:confirmButton
            acaoDestino="#{cc.attrs.managedBeanName.removeSelected()}"
            value="Remover Selecionados" />

【问题讨论】:

    标签: jsf composite-component


    【解决方案1】:

    首先,您必须指定一个方法签名,以便 JSF 知道它是方法表达式而不是值表达式,您的复合组件应如下所示:

    <composite:interface>
            <composite:attribute name="acaoDestino" required="true" method-signature="void actionListener()"
                    shortDescription="Método que será executado quando o usuário clicar no botão 'Sim'." />
    </composite:interface>
    <composite:implementation>
            <h:commandButton actionListener="#{cc.attrs.acaoDestino}" class="btn btn-primary" value="Sim">
                   <f:ajax render="@all" execute="@all" />
            </h:commandButton>
    </composite:implementation>
    

    第二,如果你没有使用 EL 2.2,你应该使用这个签名(见JSF - actionListener tag calls method which doesn't take an ActionEvent parameter):

    public void removeSelected(ActionEvent e) {
    ...
    }
    

    在这种情况下,您的方法签名属性变为:

    method-signature="void actionListener(ActionEvent e)
    

    注意:命令组件在激活时提交请求,因此在刷新整个页面时无需使用&lt;f:ajax render="@all" execute="@all" /&gt;

    【讨论】:

    • 没用,我用新信息编辑了我的帖子。我正在使用 JSF 2.2
    • @user2776409 请提供如何在您的 xhtml 页面中使用您的复合组件?
    • 你必须像这样使用它:
    • 请删除 value 属性,因为您没有在 CC 界面中声明它,我正在使用您的相同代码及其工作!
    【解决方案2】:

    你能告诉我acaoDestino到底是什么吗?支持 bean 中的方法变量?因为如果它是一个方法或变量,你必须在你的 buttonCommand action="" 或 listener=""

    中使用

    【讨论】:

    • 很好,所以尝试使用 action="emoveSelected" 或 listener="#{removeSelected"
    • 但是我需要使用 'acaoDestino' 而不是 'removeSelected()" 因为 actionListener 可以改变。
    • 你说 acaoDestino 是你 bean 中的一个方法或一个字段,我想说的是你 bean 中的一个属性?
    • acaoDestino 是复合组件中的“属性”,用于复合:实现。
    • 好的,如果你没有监听器,这意味着你的jsf版本低于2.2,在这种情况下你必须使用juste action。您能否请展示一下您的 bean 的那部分,其中您有名为 acaoDestino 的属性,如果您有它,则生成 sur,getter 和 setter 吗?
    【解决方案3】:

    尝试使用:

    <h:commandButton listener="#{myManagedBean.removeSelected()}"
                        class="btn btn-primary" value="Sim">
                        <f:ajax render="@all" execute="@all" />
                    </h:commandButton>
    

    或:

    <h:commandButton action="#{myManagedBean.removeSelected()}"
                        class="btn btn-primary" value="Sim">
                        <f:ajax render="@all" execute="@all" />
                    </h:commandButton>
    

    【讨论】:

    • listener attribute don't existis in commandButton JSF and action 给我同样的问题
    猜你喜欢
    • 2017-08-09
    • 2011-09-09
    • 2011-06-27
    • 2012-11-18
    • 2013-03-23
    • 2013-04-22
    • 2011-06-04
    • 1970-01-01
    • 2012-01-09
    相关资源
    最近更新 更多