有没有办法检测咆哮对话框何时关闭,并对该事件采取行动?
PrimeFaces 用户指南中没有为咆哮列出 ajax 事件,也没有任何 onclose 或 oncomplete javascript 处理程序属性。
我需要这个的原因是我使用了一个在打开对话框时停用的轮询器,并且我希望在关闭咆哮消息后重新激活轮询器。
在原始对话框关闭后,我正在重新激活轮询器,但由于某种原因,咆哮声的添加破坏了轮询器的重新激活。重新启动的 poller 轮询一次,直到出现咆哮,然后停止。
所以..我的想法是将轮询器的重新激活移动到咆哮关闭之后。
代码分为几个片段,一个片段有轮询器,可以通过工具栏按钮启动和停止(此处仅显示轮询器):
<h:form id="form-toolbar">
<!-- poller -->
<p:poll id="pollerDataTable"
widgetVar="p4mPollerDataTable"
interval="10"
async="true"
global="false"
update=":form-toolbar:dtItems"
listener="#{controller.refreshDataTable}"
autoStart="false" />
[snip]
</h:form>
一个片段有咆哮声:
<h:form id="form-body-growl">
<p:growl id="growlSuccess" for="success" severity="info" infoIcon="/img/LOGO_H150.png"
warnIcon="/img/LOGO_H150.png" errorIcon="/img/LOGO_H150.png"
sticky="false" life="3000"/>
<p:growl id="growlError" severity="warn, error" infoIcon="/img/LOGO_H150.png"
warnIcon="/img/LOGO_H150.png" errorIcon="/img/LOGO_H150.png"
sticky="true" globalOnly="true"/>
</h:form>
一个片段有一个命令按钮来显示对话框:
<p:commandButton id="tbBtnNew"
icon="ui-icon-plus"
title="#{facesUtilsBean.getLocalizedText(webUiConstBean.BUNDLE_BASE_NAME_UI_STRING, 'toolbar.tooltip.new')}"
actionListener="#{controller.onShowNewDialog}"
update=":form-dlgNew:new"
onsuccess="p4mDlgNew.show();"/>
<p:tooltip for="tbBtnNew" showEffect="fade" hideEffect="fade" />
另一个包含正在打开的对话框:
<!-- new dialog -->
<h:form id="form-dlgNew">
<p:dialog header="New" id="dlgNew"
widgetVar="p4mDlgNew" resizable="false" dynamic="true" modal="true" closable="false">
<div class="dialog-container">
<h:panelGrid id="new" columns="3" columnClasses="formText, formValue, formValidation" styleClass="defaultTable" style="width:100%;" rendered="#{not empty controller.editingItem}">
<ui:insert name="newDialogColumns"/>
<p:spacer/>
<p:column colspan="2">
<p:commandButton styleClass="cmdButtonSaveCancel" ajax="false"
value="#{facesUtilsBean.getLocalizedText(webUiConstBean.BUNDLE_BASE_NAME_UI_STRING, 'dialog.save.button')}"
actionListener="#{controller.onSaveNewDialog}" update=":form-toolbar:dtItems, :form-body-growl:growlSuccess, :form-body-growl:growlError"
onsuccess="p4mDlgNew.hide();" process="new"/>
<p:commandButton styleClass="cmdButtonSaveCancel" ajax="false"
value="#{facesUtilsBean.getLocalizedText(webUiConstBean.BUNDLE_BASE_NAME_UI_STRING, 'dialog.cancel.button')}"
actionListener="#{controller.onCancelNewDialog}" update=":form-toolbar:dtItems" onsuccess="p4mDlgNew.hide();" process="@this"/>
</p:column>
</h:panelGrid>
</div>
</p:dialog>
</h:form>
然后在支持 bean 中有暂停和恢复轮询的事件处理程序
public void suspendPolling() {
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.execute(POLLER_DATATABLE_CLIENT_ID + ".stop();");
}
public void resumePolling() {
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.execute(POLLER_DATATABLE_CLIENT_ID + ".start();");
}
public void onShowNewDialog(ActionEvent event) {
if (isAutoRefreshActive()) {
suspendPolling();
}
[snip]
}
/**
* Called by new button template when 'cancel' button clicked.
* Refreshes data and resumes polling if necessary.
*/
public void onCancelNewDialog(ActionEvent event) {
[snip]
if (isAutoRefreshActive()) {
resumePolling();
}
}
/**
* Called by new button template when 'accept' button clicked.
* Refreshes data and resumes polling if necessary.
*/
public void onSaveNewDialog(ActionEvent event) throws PSoftIOException {
[snip]
if (isAutoRefreshActive()) {
resumePolling();
}
}
那么,请问有没有办法将 resumePolling 功能移动到咆哮关闭之后?
或者..或者(甚至更好),一种解决原始问题的方法,即咆哮声打破了轮询器?
干杯
[编辑 ]
有关轮询器活动状态的更多信息。
我们使用 Bean 中的以下代码检查和控制轮询器的活动状态:
private ToolBarRefreshController getToolBarRefreshController() {
return (ToolBarRefreshController) FacesUtils.resolveBean("toolBarRefreshController");
}
private boolean isAutoRefreshActive() {
ToolBarRefreshController toolBarRefreshController = getToolBarRefreshController();
if (toolBarRefreshController == null) {
return false;
}
return toolBarRefreshController.isAutoRefreshActive();
}
public void startAutoRefresh() {
// nesting starting polling must be prevented
if (!isAutoRefreshActive()) {
refreshDataTable();
resumePolling();
getToolBarRefreshController().setAutoRefreshActive(true);
}
}
public void stopAutoRefresh() {
// nesting stopping polling must be prevented
if (isAutoRefreshActive()) {
suspendPolling();
getToolBarRefreshController().setAutoRefreshActive(false);
}
}