JSF – p:dataTable – p:commandButton doesn’t work even inside p:column


I have a commandButton inside a DataTable. However the "action" isn't called when I click on it (same effect with an actionListener); I added logs at the beginning of the server action, and it never shows.
Please note that the button works fine when outside from the datalist.

Here is my code:

<h:form id="compSearchForm">
    <p:dataTable var="competency" value="#{competencySearchBean.matchingCompetencies.toArray()}">
            <f:facet name="header">
                <h:outputLabel value="Title" />
            <h:outputText value="#{competency.title}" />

            <p:commandButton value="Go" id="actionButton" action="#{myBean.doAction}" />

Would you have any idea as to what the issue might be?

Best Solution

I added your button column code to an existing of mine along with a dummy method in by backing bean. The method is called correctly when I press the button it works correctly. Here is the code I added to my dataTable:

    <p:commandButton value="Go" id="actionButton" action="#{tableBean.buttonAction()}" />

Here is the buttonAction method in my backing bean:

public void buttonAction()
        int a = 0;
        for(int i = 0; i < 100; i++)
            a = i;

I put a breakpoint on this method, so I know it is getting called when I click the button. I went a step further and used your datatable code (with my data source) and the method is still being called when I press the button. I don't know what development environment you are using, but if it has a debug mode put a breakpoint on your doAction method, and a few other strategic locations in your bean, then run your project in debug mode to see what is going on.

Related Question