0

I have a page with p:datatable and dynamic columns. I'm trying to add a command button to the headers with an f:attribute as a value for the command button click. the problem is I don't get to the server at all when pressing the header button. here is a code snipet

<p:dataTable >
    <p:columns value="#{controller.columnsTitles}" var="column" columnIndexVar="colIndex">
        <f:facet name="header">
            <p:panel >
                <table>
                    <tr>
                        <th>
                            <p:panel>
                                #{column.label}
                            </p:panel>
                        </th>
                    </tr>
                    <tr>
                    <th>
                        <h:panelGroup >
                            <p:commandButton value="Add" actionListener="#{controller.doStaff}">
                                <f:setPropertyActionListener value="#{column.value}" target=#{controller.selectedToEdit}" />
                            </p:commandButton>
                        </h:panelGroup>
                    </th>
                </tr>
            </table>
        </p:panel>

    </f:facet>
<p:column>
    ......
</p:column>
</p:columns>
</p:dataTable>

[Edit] I found a solution for this issue. To the commandbutton I added an onClick event that pass the parameter selectedToEdit to a javascript function that in her turn calls a p:remoteCommand that pass the parameter to the server. I also changed the actionListener of the commandButton to action and now it's working.

Now the code looks as follow:

<script>
function jsFunc(param)
{
    command([{name:'selectedToEdit',value:selectedToEdit}]);
}
</script>
.....
<p:remoteCommand name="command" actionListener="#{controller.selectedToEdit}" />
<p:commandButton value="Add" action="#{controller.doStaff}" onclick="jsFunc('#{column.value}')" />
4

0 回答 0