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");
}
Please help me get the page change(automatically) event or suggest another way. Thanks in advance.