p:dataTable 在对话框关闭时不显示来自数据库的更新记录
p:dataTable not showing updated records from database on Dialog close
我需要你帮助我在关闭 Dialog
时刷新 dataTable
组件。我尝试了很多方法来刷新 dataTable
,但它没有检索更新的记录,除非我通过单击 URL 旁边的 "Go" 按钮刷新了整个页面地址栏。
xhtml代码:
<h:form id="Requests">
<h:panelGroup id="table">
<p:fieldset id="Pendings" legend="Pending Requests">
<div id="refresh">
<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. Date" sortBy="#{hr.requestDate}" filterMatchMode="contains" filterBy="#{hr.requestDate}" >
<h:outputText value="#{hr.requestDate}"/>
</p:column>
<p:column>
<f:facet name="header">View</f:facet>
<p:commandButton id="submitbutton" update=":Requests:#{hr.dialogueName} "
oncomplete="PF('#{hr.certificateDialogue}').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{hr}" target="#{hrd.selectedRequest}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</div>
</p:fieldset>
</h:panelGroup>
<p:dialog id="CertificateDialog" header="Cert1" widgetVar="CertificateDialog" >
<p:ajax event="close" update=":Requests" listener="#{hrd.UpdateDatatable}"/>
</p:dialog>
</h:form>
我尝试只更新数据表,但没有刷新。虽然,我尝试使用@form 和@all 更新完整表单,但数据表再次没有刷新。
updateDataTable 方法:
public void UpdateDatatable(CloseEvent event) {
RequestContext.getCurrentInstance().update(":Requests");
}
当您尝试使用 RequestContext.update()
从 ManagedBean
更新组件时,您不应使用相对组件 ID,因为您没有任何关联。
要解决您的问题,请在您的侦听器中删除 Requests
之前的 :
。
RequestContext.getCurrentInstance().update("Requests");
如果您觉得从托管 bean 更新组件,会增加凝聚力。您可以随时使用 p:remoteCommand
can call if 来自您的 javascript。
<p:remoteCommand name="updateTable" process="@this" partialSubmit="true" update=":Results" />
并且您可以从 javascript 中调用上面的 remoteCommand
或者在您的情况下从对话框中调用,如下所示:
<p:dialog onhide="updateTable()">
...
</pdialog>
我的建议是将 p:dialog
移出您放置 dataTable
的 h:form
。因为将来如果您遇到需要在 p:dialog
仍然打开时更新 h:form
的情况,更新放置 p:dialog
的自己的 h:form
,会导致对话框 p:dialog
突然关闭。
如果您的 p:dialog
出局 h:form
,那么您可能不需要 UpdateDatatable()
侦听器本身。 update
来自您的 p:ajax
会为您完成这项工作。
我需要你帮助我在关闭 Dialog
时刷新 dataTable
组件。我尝试了很多方法来刷新 dataTable
,但它没有检索更新的记录,除非我通过单击 URL 旁边的 "Go" 按钮刷新了整个页面地址栏。
xhtml代码:
<h:form id="Requests">
<h:panelGroup id="table">
<p:fieldset id="Pendings" legend="Pending Requests">
<div id="refresh">
<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. Date" sortBy="#{hr.requestDate}" filterMatchMode="contains" filterBy="#{hr.requestDate}" >
<h:outputText value="#{hr.requestDate}"/>
</p:column>
<p:column>
<f:facet name="header">View</f:facet>
<p:commandButton id="submitbutton" update=":Requests:#{hr.dialogueName} "
oncomplete="PF('#{hr.certificateDialogue}').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{hr}" target="#{hrd.selectedRequest}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</div>
</p:fieldset>
</h:panelGroup>
<p:dialog id="CertificateDialog" header="Cert1" widgetVar="CertificateDialog" >
<p:ajax event="close" update=":Requests" listener="#{hrd.UpdateDatatable}"/>
</p:dialog>
</h:form>
我尝试只更新数据表,但没有刷新。虽然,我尝试使用@form 和@all 更新完整表单,但数据表再次没有刷新。
updateDataTable 方法:
public void UpdateDatatable(CloseEvent event) {
RequestContext.getCurrentInstance().update(":Requests");
}
当您尝试使用 RequestContext.update()
从 ManagedBean
更新组件时,您不应使用相对组件 ID,因为您没有任何关联。
要解决您的问题,请在您的侦听器中删除 Requests
之前的 :
。
RequestContext.getCurrentInstance().update("Requests");
如果您觉得从托管 bean 更新组件,会增加凝聚力。您可以随时使用 p:remoteCommand
can call if 来自您的 javascript。
<p:remoteCommand name="updateTable" process="@this" partialSubmit="true" update=":Results" />
并且您可以从 javascript 中调用上面的 remoteCommand
或者在您的情况下从对话框中调用,如下所示:
<p:dialog onhide="updateTable()">
...
</pdialog>
我的建议是将 p:dialog
移出您放置 dataTable
的 h:form
。因为将来如果您遇到需要在 p:dialog
仍然打开时更新 h:form
的情况,更新放置 p:dialog
的自己的 h:form
,会导致对话框 p:dialog
突然关闭。
如果您的 p:dialog
出局 h:form
,那么您可能不需要 UpdateDatatable()
侦听器本身。 update
来自您的 p:ajax
会为您完成这项工作。