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}')" />
user1927865
  • 135
  • 1
  • 1
  • 8
  • 1
    please try to add ajax="false" or use pure jsf commandbutton for testing purpose somewhere in your code there is a bug – Subodh Joshi Jul 03 '13 at 09:03
  • primefaces uses `ajax="true"` as default. if you want normal button behaviour you need to set if to false explicitly – Przemek Jul 03 '13 at 09:09
  • Thanks for your reply's. non of your advices are not working for me. – user1927865 Jul 03 '13 at 11:57
  • what does you log say when you press the button? is the bean reachable? how does your method in the bean look? – Przemek Jul 03 '13 at 13:39
  • @Przemek I found a solution. please see my edit. – user1927865 Jul 03 '13 at 14:57
  • You can pass values to the bean in a jsf native way. Take all look at http://stackoverflow.com/questions/9701590/passing-parameters-between-managed-beans-with-request-scope or this http://stackoverflow.com/questions/4888942/viewparam-vs-managedpropertyvalue-param-id – Przemek Jul 03 '13 at 15:24

0 Answers0