99maas 99maas - 2 months ago 29
Ajax Question

How to refresh a p:dataTable after closing a dialog in PrimeFaces?

I need your help in refreshing the whole

dataTable
with pagination once I closed the
dialog
. With the current code after closing the
dialog
, the
dataTable
will be refreshed if the selected item is in the first page and I can see the updates.

However, if I have searched for a particular item using the filter and then I clicked on the view icon to view the dialog and then close the
dialog
. The
dataTable
will not be refreshed unless I deleted the searched item from the filter and then I tried to search for it again, I will find the updates.

The code for the page is:

<h:form id="Requests">
<p:dataTable id="PendingRequests"
var="hr"
value="#{hrd.pendingRequests}"
paginator="true"
rows="15"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15"
paginatorPosition="bottom"
filteredValue="#{hrd.filteredPendingRequests}">

<p:column headerText="Req. No." sortBy="#{hr.reqNo}" filterMatchMode="contains" filterBy="#{hr.reqNo}">
<h:outputText value="#{hr.reqNo}"/>
</p:column>

<p:column headerText="Print Count" filterMatchMode="contains" filterBy="#{hr.printCount}">
<h:outputText value="#{hr.printCount}"/>
</p:column>

<p:column>
<f:facet name="header">View</f:facet>
<p:commandButton id="submitbutton"
update=":Requests:#{hr.dialogueName} "
oncomplete="PF('#{hr.certificateDialogue}').show()"
title="View">

<f:setPropertyActionListener value="#{hr}" target="#{hrd.selectedRequest}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>


And the code for the
dialog
is:

<p:dialog id="employmentCertificateDialog"
header="Certificate"
widgetVar="employmentCertificateDialog"
modal="true"
showEffect="fade"
hideEffect="fade"
resizable="true">

<p:ajax event="close"
listener="#{hrd.UpdateDatatable}"
update=":Requests:PendingRequests"/>
</p:dialog>


And the
UpdateDatatable()
method has the code:

public void UpdateDatatable(CloseEvent event) {

listPendingRequests = new ArrayList<PendingRequests>();

try {
//Select Statement

while (result.next()) {
PendingRequests pendingList = new PendingRequests();
reqNo = result.getString("REQ_SEQ_NO");
printCount = result.getString("DOC_PRINTED_CNT" + 1);
pendingList.setReqNo(reqNo);
pendingList.setPrintCount(printCount);
}

} catch (Exception e) {
e.printStackTrace();
}
}

Answer

Add the widgetvar to the dataTable widgetVar="dtWidgetVar"

and then:

<p:ajax event="close" listener="#{hrd.UpdateDatatable}" update=":Requests:PendingRequests" onComplete="PF('dtWidgetVar').filter()" />