繁体   English   中英

JSF中出现错误的复合组件

[英]Composite component with Error in JSF

好吧,下面是复合组件:

<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>

当我单击此commandButton时,两次调用了一个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: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标记调用不带ActionEvent参数的方法 ):

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

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

method-signature="void actionListener(ActionEvent e)

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

你能告诉我有关acaoDestino的确切信息吗? 您的支持bean中的方法var? 因为如果是方法或变量,则必须在buttonCommand action =“”或listener =“”中使用

尝试使用:

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM