0

I'm trying to create a composite component receveing some arguments like my ManagedBean.

This is my composite component:

<composite:interface>
    <composite:attribute name="label" required="true"
        shortDescription="Valor que será mostrado no campo. Ex: Id" />
    <composite:attribute name="methodName" required="true"
        shortDescription="Nome do método que realiza o get ao campo. Ex: getId" />
    <composite:attribute name="managedBeanName"
        type="br.com.jwebbuild.mb.BasicCrudMBImpl" required="true"
        shortDescription="Nome do managedBean do componente" />
</composite:interface>

<composite:implementation>

    <h:commandLink value="#{cc.attrs.label}"
        actionListener="#{cc.attrs.managedBeanName.orderby(cc.attrs.methodName)}"
        title="Clique para ordernar">
        <f:ajax execute="@this" render="@form" />
    </h:commandLink>
    <i class="fa fa-bars fa-fw"></i>

</composite:implementation>

When i try to execute i got error: MethodNotFoundException. But if i change this line

    actionListener="#{cc.attrs.managedBeanName.orderby(cc.attrs.methodName)}"

for this:

    actionListener="#{bancaMB.orderby(cc.attrs.methodName)}"

Everything works fine, but why my composite don't works with cc.attrs ? I have anothers composite components that receive same ManagedBean and works fine.

Look, in this code i'm using this composite component:

<jw:orderColumLink managedBeanName="#{bancaMB}"
                                                    methodName="getId" label="Id" />

Edit 1

This code bellow works normal, and use managedBean parameter method:

<composite:interface>
    <composite:attribute name="idDataTable" default="dataTableListagem"
        shortDescription="ID do DataTable. Usado para referencia em outras partes do código" />
    <composite:attribute name="managedBeanName"
        type="br.com.jwebbuild.mb.BasicCrudMBImpl" required="true"
        shortDescription="Nome do managedBean do componente" />

    <composite:attribute name="showSelectAll" type="boolean" default="true"
        shortDescription="Mostra a coluna para selecionar todos os registros. Padrão = true" />

    <composite:attribute name="showEditRemove" type="boolean"
        default="true"
        shortDescription="Mostra a coluna para editar e remover um registro. Padrão = true" />

    <composite:attribute name="targetPage" type="String"
        shortDescription="Caminho para acesso a página de inserção ou alteração do registro." />

</composite:interface>

<composite:implementation>

    <div class="table-responsive">
        <h:dataTable var="bean" value="#{cc.attrs.managedBeanName.beans}"
            id="#{cc.attrs.idDataTable}" styleClass="table table-hover"
            binding="#{cc.attrs.managedBeanName.dataTable}">
            <h:column rendered="#{cc.attrs.showSelectAll}"
                headerClass="smallColumn">
                <f:facet name="header">
                    <h:selectBooleanCheckbox
                        valueChangeListener="#{cc.attrs.managedBeanName.selectAll}">
                        <f:ajax execute="@form" render="@form" />
                    </h:selectBooleanCheckbox>
                </f:facet>

                <h:selectBooleanCheckbox value="#{bean.selected}">
                    <f:ajax execute="@this" render="@this" />
                </h:selectBooleanCheckbox>
            </h:column>

            <composite:insertChildren />

            <h:column rendered="#{cc.attrs.showEditRemove}"
                headerClass="smallColumn">
                <h:link styleClass="btn btn-default"
                    outcome="#{cc.attrs.managedBeanName.redirectAlterarBean(cc.attrs.targetPage,bean.id)}">
                    <i class="fa fa-pencil-square-o fa-lg"></i> Editar
                    </h:link>
            </h:column>

        </h:dataTable>
    </div>
    <!-- /.table-responsive -->
</composite:implementation>

Edit 2 I'm using "com.sun.faces" JSF 2.2.6 (jsf-api, jsf-impl) Full StackTrace bellow:

Fev 18, 2015 1:44:41 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
Advertência: Method not found: br.com.cardoso.mb.BancaMBImpl@24cc8c62.orderby()
javax.el.MethodNotFoundException: Method not found: br.com.cardoso.mb.BancaMBImpl@24cc8c62.orderby()
    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:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIData.broadcast(UIData.java:1108)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    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:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    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 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)

Fev 18, 2015 1:44:41 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
Grave: javax.el.MethodNotFoundException: Method not found: br.com.cardoso.mb.BancaMBImpl@24cc8c62.orderby()
    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:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIData.broadcast(UIData.java:1108)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    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:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    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 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)
Shelly
  • 1,035
  • 5
  • 27
  • 51
  • Should work fine and works just fine for me on Tomcat 8 and WildFly 8. Which JSF/container/EL impl/version are you using? Can you please post the full stack trace? – BalusC Feb 18 '15 at 07:41
  • @BalusC, I edited my post with full StackTrace and informations about JSF version – Shelly Feb 18 '15 at 16:45
  • @BalusC, I beleive that if you said it should work fine then it should work fine, but for my understanding I read that for methods to work inside composite implementation we need to provide method-signature, also in the Java EE 6 tutoriel they only talk about bean properties when talking about passing a managed bean. So could you explain to me why that should work? thanks – Tarik Feb 18 '15 at 17:33
  • @Tarik, i can ensure that works, i can call method using ManagedBean as parameter. – Shelly Feb 18 '15 at 17:41
  • @Shelly Yes I do beleive that, I just hope to understand more from BalusC, that's why my question :) (I removed my answer as it's not correct and may mislead other SO users) – Tarik Feb 18 '15 at 17:44
  • I see that you're using Tomcat. Which version exactly? Older versions had similar bugs in their Apache EL impl. The second example "works fine" because `` just evaluates as a value expression returning a `String`, not as a method expression which should invoke an action method. You should also have noticed that the `` expression was invoked during rendering the HTML output, not during clicking the link. – BalusC Feb 18 '15 at 18:18
  • I'm using Tomcat 7, i should update to tomcat 8 ? – Shelly Feb 18 '15 at 18:19
  • Which 7 version exactly? You could also go for latest 7. – BalusC Feb 18 '15 at 18:20
  • Tomcat version 7.0.12 – Shelly Feb 18 '15 at 18:21
  • 1
    That's quite old, so upgrade it, yes :) – BalusC Feb 18 '15 at 18:23
  • Right, i will upgrade test again and return here with a feedback. – Shelly Feb 18 '15 at 18:24
  • 1
    @Tarik: you can actually parameterize bean, method and arguments separately like OP did. See also a.o. http://stackoverflow.com/q/11994339 and http://stackoverflow.com/q/13748019 Only, I'd rename that confusing attribute name `managedBeanName` to `managedBean` as it actually refers a managed bean instance, not a plain vanilla string representing managed bean name ;) – BalusC Feb 18 '15 at 18:25
  • I finally found the related/duplicate question: http://stackoverflow.com/q/4385545 In the comment of my answer you can see that it's fixed in 7.0.24, along with a link to another question concerning the same problem http://stackoverflow.com/q/8795009/ @Shelly, which do you accept as duplicate? – BalusC Feb 18 '15 at 18:27
  • @BalusC, let me try first but i can't accept as duplicate because i didn't know the cause of problem. – Shelly Feb 18 '15 at 18:42
  • @Shelly he told you that the cause of your problem is a bug in EL implementation of Tomcat, and in his answers, he provided the link to the issue: https://bz.apache.org/bugzilla/show_bug.cgi?id=50449 – Tarik Feb 18 '15 at 19:32
  • I know that Tarik, ready again my answer. I told that i "didn't know" but now i know. – Shelly Feb 18 '15 at 19:41
  • @BalusC, i tested with new tomcat 7.0.59 version and worked very well, thanks for help. – Shelly Feb 18 '15 at 22:39

0 Answers0