Primefaces datatable selection multiple using ajax event no call methode

harimu picture harimu · May 29, 2015 · Viewed 9.7k times · Source

I want to call a listener using ajax event rowSelectCheckBox on Lazy Data Model with selected multiple. I create a methode in my backing bean, but this method is not called.

Can anyone help to solve this?

my xhtml:

<h:form id="frmDataTableMutasi">
<p:outputLabel value="Daftar Toko Akan Dimutasi"
    styleClass="outputlabel-title" />
<br />
<p:dataTable widgetVar="widgetDataModel" var="dataModel"
    id="dataTable" value="#{tokoListBean.lfaStoreDataModel}" lazy="true"
    paginator="true" rows="5" paginatorPosition="bottom"
    emptyMessage="No record found"
    selection="#{tokoListBean.selectedLfaStore}"
    selectionMode="multiple"
    currentPageReportTemplate="{currentPage}/{totalPages}"
    paginatorTemplate="{FirstPageLink} {PreviousPageLink}      {CurrentPageReport} {NextPageLink} {LastPageLink}"
    rowsPerPageTemplate="5,10,15">

    <p:ajax event="rowSelectCheckbox" 
        listener="#{tokoListBean.onRowSelect}" update=":frmBtn:btnMutasi" />
    <p:ajax event="rowUnselectCheckbox"
        listener="#{tokoListBean.onRowUnselect}" update=":frmBtn:btnMutasi" />

    <p:column selectionMode="multiple"
        style="width:16px;text-align:center" />

    <p:column>
        <h:outputText value="#{dataModel.storeCode}" />
    </p:column>
    <p:column>
        <h:outputText value="#{dataModel.storeName}" />
    </p:column>
    <p:column>
        <h:outputText value="#{dataModel.snStoreType}" />
    </p:column>

    </p:dataTable>

my backing bean:

public void onRowSelect(SelectEvent event) {
    System.out.println("onRowSelect");
    this.enableBtnMutasi = false;
}

public void onRowUnselect(UnselectEvent event) {
    System.out.println("onRowUnselect");
    this.enableBtnMutasi = true;
}

Answer

nosnhoj picture nosnhoj · Nov 13, 2017

try delete widgetVar="widgetDataModel"

and add following code:

<p:ajax event="toggleSelect" listener="#{tokoListBean.onRowToggle()}" update=":frmBtn:btnMutasi"/>          
<p:ajax event="rowSelectCheckbox" listener="#{tokoListBean.onRowSelect}" update=":frmBtn:btnMutasi"/>          
<p:ajax event="rowUnselectCheckbox" listener="#{tokoListBean.onRowUnselect}" update=":frmBtn:btnMutasi"/>          
<p:ajax event="rowSelect" listener="#{tokoListBean.onRowSelect}" update=":frmBtn:btnMutasi"/>          
<p:ajax event="rowUnselect" listener="#{tokoListBean.onRowUnselect}" update=":frmBtn:btnMutasi"/>