我有一个选项卡视图,只要用户选择该选项卡,我就想在其中刷新该选项卡的内容。我还希望在刷新选项卡时弹出模式对话框。
这是带有 tabChange ajax 事件处理程序的 tabView
<p:dialog widgetVar="statusDialog" modal="true" draggable="false" minimizable="false" appendToBody="true" closable="false" header="Processing..." resizable="false" maximizable="false">
<p:graphicImage library="assets" name="ajax-loader.gif"></p:graphicImage>
</p:dialog>
<p:tabView id="tabview" orientation="top" dynamic="false">
<p:ajax event="tabChange" listener="#{bean.tabChangeListener}"></p:ajax>
<p:tab title="tab1">
<ui:include src="/WEB-INF/views/tab1.xhtml"/>
</p:tab>
<p:tab title="tab2">
<p:remoteCommand actionListener="#{bean.refreshData}" update="someTab2ElementID" name="refresh" global="true" onstart="statusDialog.show()" oncomplete="statusDialog.hide()"/>
<ui:include src="/WEB-INF/views/tab2.xhtml"/>
</p:tab>
</p:tabView>
这是 tabChangeListener:
public void tabChangeListener(TabChangeEvent event) {
if ( event.getTab().getId().equalsIgnoreCase("tab2") ) {
RequestContext.getCurrentInstance().execute("refresh()");
}
}
刷新远程命令按预期被调用,但我的状态对话框从未显示。如果通过单击按钮触发相同的远程命令,则会出现状态对话框。 JavaScript 控制台中没有错误。
当 RequestContext.execute() 触发remoteCommand时,为什么不显示statusDialog?如何让它显示?我什至尝试将 statusDialog.show() 添加到execute(),但没有帮助。
我想到了。这是解决方案:
<h:outputScript>
var blockCount=0;
function showStatus() {
if (blockCount==0) statusDialog.show();
blockCount++;
};
function hideStatus() {
blockCount--;
if (blockCount==0) statusDialog.hide();
};
</h:outputScript>
<p:ajaxStatus onstart="showStatus();" onsuccess="hideStatus();" onerror="blockCount=0;statusDialog.hide();errorDialog.show();"/>
<p:remoteCommand actionListener="#{bean.refreshData}" update="someTab2ElementID" name="refresh" global="true" onstart="showStatus()" oncomplete="hideStatus()"/>
显然,我的状态对话框没有显示的原因是另一个 Ajax 调用完成并调用了 statusDialog.hide(),而我的刷新() 事情正在进行中。上面的 JS 代码维护一个计数器,记录正在进行的 Ajax 调用数量,并且仅在所有调用完成后才会隐藏状态对话框。现在按预期工作了!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)