0

My issue is I am removing the last row (data) of the 2nd page of the Datatable. After successful deletion the Datatable page will be changed to previous page. After that I am not able to remove the row from the 1st page, since the page change happened automatically.

I think the datatable component page was not set when the last row was deleted from 2nd page.

If I change the page manually from 2nd to 1st, I am able to delete the record on the first page.

please find the code of datatable:

<p:outputPanel id="associatetable">
     <p:dataTable first="#{masterBean.first}" 
    value="#{myBean.AssociationDtoList}"
    var="itasc" id="ascTable"
    currentPageReportTemplate="{currentPage} / {totalPages}"
    rowKey="#{itasc}" rows="20" paginator="true"
    paginatorPosition="bottom" rowIndexVar="idx"
    paginatorTemplate=" {FirstPageLink} {PreviousPageLink} {PageLinks}   {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="20,50,100"
    emptyMessage="#{msg['pds.no_records_found']}"
     styleClass="">
    <p:column headerText="#" styleClass="width-10">
        <h:outputText value="#{idx+1}" />
    </p:column>

    <p:column headerText="#{msg['pds.code']}"
        styleClass="text-left">
        <h:outputText value="#{itasc.code}" />
    </p:column>

    <p:column headerText="#{msg['pds.name']}"
        styleClass="text-left">
        <h:outputText
            value="#{masterBean.processLength(itasc.name,20)}" />
    </p:column>
    <p:column headerText="#{msg['pds.profile']}"
        styleClass="text-left">
        <h:outputText value="#{itasc.profile}" />
    </p:column>

    <p:column headerText="#{msg['pds.select']}"
        styleClass="associate">
        <p:commandButton value="#{msg['pds.remove']}"
            id="rmv"
            class="btn btn-info cus-btn btn-sm btn-delete"
            immediate="true"
            disabled="#{myBean.action eq 'View'}"
            action="#{myBean.setAssociationDto(itasc)}">
            <f:setPropertyActionListener value="#{itasc}"
                for="rmv"
                target="#{myBean.AssociationDto}" />
            <p:ajax />
            </p:commandButton>
        </p:column>
    </p:dataTable>
</p:outputPanel>        

and this is my dialog:

<p:dialog header="#{msg['pds.confirm_del']}" widgetVar="removeDlg"
    modal="true" position="center" resizable="false"
    styleClass="cus-model-popup">
    <h:form>
        <h5>#{msg['pds.remove_msg']}</h5>

        <h:commandButton
            styleClass="pull-right btn btn-info btn-sm left-mspace"
            value="#{msg['pds.no']}" onclick="PF('removeDlg').hide();">
            <f:ajax />
        </h:commandButton>
    <h:commandButton class="blue-button pull-right btn btn-info btn-sm"
        value="#{msg['pds.yes']}"
        action="#{myBean.deAssociateProfiles}"
        onclick="PF('removeDlg').hide();">
        <f:ajax />
    </h:commandButton>

    </h:form>
</p:dialog>

This is my Bean code: The Bean is sessionScoped

public String setAssociationDto(AssociationDto dto) {
    log.info("AssociationDto Called " + dto);
    AssociationDto = new AssociationDto();
    AssociationDto.setId(dto.getId());
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("PF('removeDlg').show();");
    return null;
}

public void deAssociateProfiles() {

    log.info("deAssociateProfiles Called "
            + AssociationDto);
    int keyLocation = AssociationDtoList
            .indexOf(AssociationDto);
    AssociationDtoList.remove(keyLocation + 0);
    AssociationDto = new AssociationDto();
    RequestContext.getCurrentInstance().update("form:form:associatetable");
}

datatable

Please help me get the page change(automatically) event or suggest another way. Thanks in advance.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • The documentation lists an ajax behaviour event "page" and is very extensive for dataTable. Please have a look at http://www.primefaces.org/showcase/ui/data/datatable/selection.xhtml and click "documentation". Once it has loaded, you can browse the documentation by clicking right or left on a page. Hope this helps. – Gunnar Aug 03 '16 at 15:12
  • When you press the delete button on the first page, will your action method be called? If so, there is a rendering problem. Are there any errors in your browser console? Suggestion: How about to use multiple checkboxes to delete elements instead of a button for single elements? – chaeschuechli Aug 03 '16 at 19:33
  • Thanks for your reply @Gunnar, ajax 'page' event is called when I change the page manually. But my scenario is if there is more than one page, in last page if I remove the last row then the page was changed to previous page. And in that time page event was not triggered. I have tried page event also. – seenivasan Aug 04 '16 at 02:28
  • @chaeschuechli. The action was not called. My scenario is if there is more than one page, in last page if I remove the last row then the page was changed to previous page. After that i was not able to remove the row on that page. When i click the remove button, action was not called. – seenivasan Aug 04 '16 at 02:42

0 Answers0