如何在 PrimeFaces 中关闭对话框后刷新 p:dataTable?

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

关闭 dialog 后,我需要你的帮助来刷新整个 dataTable 的分页。使用关闭 dialog 后的当前代码,如果所选项目在第一页中并且我可以看到更新,dataTable 将被刷新。

但是,如果我使用过滤器搜索了特定项目,然后单击查看图标查看对话框,然后关闭 dialogdataTable 不会刷新,除非我从过滤器中删除了搜索到的项目,然后我尝试再次搜索它,我会找到更新。

该页面的代码是:

<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>

dialog 的代码是:

<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>

并且UpdateDatatable()方法有代码:

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();
    }
}

将 widgetvar 添加到 dataTable widgetVar="dtWidgetVar"

然后:

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

希望对您有所帮助:

<p:dialog id="dialog-test" onHide="refreshTable();">
  ...
</p:dialog>

放在页面末尾:

<p:remoteCommand name="refreshTable" action="#{hrd.UpdateDatatable}"
                 partialSubmit="true" process="@this" update="Requests" />

如果您需要将信息从对话框发送到 backBean,您可能需要更改流程,添加要发送的对话框 ID 或元素 ID:

<p:remoteCommand name="refreshTable" action="#{hrd.UpdateDatatable}"
                 partialSubmit="true" process="@this, dialog-test" update="Requests" />

祝你好运!