0
votes

Using p:treetable selectionMode="checkbox", I am trying to have a checkbox on the header so that selecting it would select all the checkboxes in all the rows of the treetable. All my attempts to invoke the p:ajax listener method processSelectAllRows have failed. I was able to get this done using p:datatable and need the same functionality using p:treetable. Any help will be greatly appreciated.

Below is the code:

        <h:form id="searchFormId">
        <p:panel id="searchPanelId">

            <p:outputPanel id="ResultsPanelId">
                <p:treeTable id="resultsTreeTableId" value="#{aBean.resultsRoot}"
                    scrollRows="20" scrollable="true" var="aNode"
                    selectionMode="checkbox" selection="#{aBean.selectedResultNodes}">
                    <p:ajax event="select" listener="#{aBean.onNodeSelect}"
                        update="resultsTreeTableId" />
                    <p:ajax event="unselect" listener="#{aBean.onNodeUnselect}"
                        update="resultsTreeTableId" />
                    <p:column>
                        <f:facet name="header">
                            <p:selectBooleanCheckbox id="allChkb" name="allChkb"
                                value="#{aBean.selectAll}">
                                <p:ajax listener="#{aBean.processSelectAllRows}"
                                    process="@this" update="resultsTreeTableId" />
                            </p:selectBooleanCheckbox>
                        </f:facet>
                        <h:outputText value="#{aNode.name}" />
                    </p:column>
                </p:treeTable>
            </p:outputPanel>

        </p:panel>
    </h:form>

Here is the listener method

public void processSelectAllRows(AjaxBehaviorEvent event) {
System.out.println("Select all rows.");}

Environment: 1) Primefaces 3.5 (Won't be able to upgrade any time soon) 2) myfaces-bundle 2.1.15 3) Tomcat server 4) Java 1.7

1

1 Answers

0
votes

Instead of AjaxBehaviorEvent you can use NodeSelectEvent.

NodeSelectEvent is a subclass of AjaxBehaviorEvent present in Primefaces 3.5 API. If you is using a not final primefaces version is better use Primefaces Objects instead of Faces Objects.

Hope I have help you! :)