0
votes

I have p:datatable as

 <p:dataTable id="tasktable" rows="5"  paginator="true" paginatorPosition="bottom" rowsPerPageTemplate="5,10,25" editable="true" editMode="row" reflow="true"
         value="#{taskBean.taskList}" selectionMode="multiple" binding="#{table}" rowKey="#{currentrow[0]}" selection="#{taskBean.selectedTaskList}" var="currentrow"}">

<p:column headerText="Select" id="checkboxSelect" selectionMode="multiple" styleClass='text-md-center com-wdth-5 white'>

</p:column>

<f:facet name="header">
    <div>
        <p:commandButton id="toggler" type="button" value="Select Columns" icon="ui-icon-calculator" styleClass="btn ad-btn-danger padd mr-b0"/>
        <p:columnToggler datasource="tasktable" trigger="toggler" />
    </div>
</f:facet>
<p:column id="sno" styleClass="com-wdth-5">
    <f:facet name="header"> #{msg['CHSN']} </f:facet> 
    <h:outputLabel value="#{table.rowIndex + 1}"/>  
</p:column>
.
.
.
 <p:ajax event="rowSelect" listener="#{taskBean.onRowSelect}" update="@form"/>
</p:dataTable>

With event="rowSelect" and selectionMode multiple, With backing bean code as

public void onRowSelect(SelectEvent event) {

    System.out.println("selectedTaskList = "+selectedTaskList.size());
}

But this rowSelect is never fired and checkbox are not selectable, but if I remove selectionMode="multiple" from p:dataTable, selection enables but still event is not fired. And selectedTaskList is just an arrayList defined globally as: private List selectedTaskList = new ArrayList<>();

1
1) No minimal reproducible example (e.g. does removing the editable, binding, css make it work?, where is the bean), 2) No version info, 3) No info about what was debugged (client and server-side). Please improve the questionKukeltje
Just my curiosity/ignorance, using #{currentrow[0]}, which field is used? Alphabetic / definition order? Others? Works?WoAiNii
@WoAiNii I am passing the data in dataTable as List of Object[], so at currentrow[0] in managed bean I am getting primary key id of row that I have passed.John
ok So I added these events, <p:ajax event="rowSelect" listener="#{taskBean.onRowSelect}" update="@form" /> <p:ajax event="rowSelectCheckbox" listener="#{taskBean.onRowSelect}" update="@form" /> <p:ajax event="toggleSelect" listener="#{taskBean.onRowSelect}" update="@this"/>,but this toggleSelect to select all rows gives exception of method not foundJohn
rows are selectable now after applying these events!John

1 Answers

0
votes

I was missing other p:dataTable events. I rectified it using these events

<p:ajax event="rowSelect" listener="#{taskBean.onRowSelect}" update="@this taskToolbar" />
<p:ajax event="rowUnselect" listener="#{taskBean.onRowUnselect}" update="@this taskToolbar" />
<p:ajax event="rowSelectCheckbox" listener="#{taskBean.onRowSelect}" update="@this taskToolbar" />
<p:ajax event="rowUnselectCheckbox" listener="#{taskBean.onRowUnselect}" update="@this taskToolbar" />
<p:ajax event="toggleSelect" process="@this" update="@this taskToolbar" listener="#{taskBean.onAllRowSelect}"/>

And My Backing Bean Code

public void onRowSelect(SelectEvent event) {
        displayTag();
    }

    public void onRowUnselect(UnselectEvent event) {
        displayTag();
    }

    public void onAllRowSelect(AjaxBehaviorEvent event) {
        displayTag();
    }

    public void displayTag() {
        if (selectedTaskList != null && !selectedTaskList.isEmpty()) {
            hideTag = true;
        } else {
            hideTag = false;
        }
    }

Where selectedTaskList is the list in which I am saving selected rows of table