jsfactionlistenercomposite-componentcommandbuttonmethodexpression

Calling a void method from a composite component


I'm trying to build a composite JSF component and I'm having some trouble calling a method. My component has a few inputs inside a and a add button responsible for adding more objects do the list that feeds the repeat. I want that button to call a different method according to the Managed Bean responsible for the page that it is responsible for (so it should be a variable set in each xhtml). But everytime I hit the button, I get the exception message:

The class 'com.test.TestMB' does not have the property 'addAction'.

This is my component:

<composite:interface>
    <composite:attribute name="id" required="false"  />
    <composite:attribute name="value" required="true"  />
    <composite:attribute name="addAction" required="true" />
</composite:interface>

<composite:implementation>
    <ui:repeat value="#{cc.attrs.value}" >      
        <!-- some inputs and other components -->
    </ui:repeat>
    <p:commandButton actionListener="#{cc.attrs.addAction}" />
</composite>

And this is my implementation:

                <cc:compositecomp id="component"
                value="#{testMB.list}"
                addAction="#{pessoaJuridicaMB.addToListMethod}" />

My TestMB class not only contains the method but also works fine if I change the button to:

<p:commandButton actionListener="#{testMB.addToListMethod}" />

The addToListMethod is something very simple:

public void addToListMethod() {
list.add(model); }

Any ideia of what is wrong and how can I fix it?


Solution

  • You have to add the method-signature attribute to the addAction attribute in the interface definition. So replace this:

    <composite:attribute name="addAction" required="true" />
    

    by this:

    <composite:attribute name="addAction" required="true" 
        method-signature="void addAction(javax.faces.event.ActionEvent)" />