在Primefaces RequestContext.execute()调用中无法显示对话框 [英] Cannot show dialog in Primefaces RequestContext.execute() call

查看:83
本文介绍了在Primefaces RequestContext.execute()调用中无法显示对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tabview,无论何时用户选择一个特定的选项卡,我都希望在其中刷新该选项卡的内容.我还希望在刷新选项卡时弹出模式对话框.

I have a tabview in which I want to refresh contents of one specific tab whenever user selects that tab. I also want modal dialog to pop up while tab is being refreshed.

这是带有tabChange ajax事件处理程序的tabView

Here is tabView with tabChange ajax event handler

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

Here is tabChangeListener:

public void tabChangeListener(TabChangeEvent event) {
    if ( event.getTab().getId().equalsIgnoreCase("tab2") ) {
                RequestContext.getCurrentInstance().execute("refresh()");
    }
}

刷新remoteCommand正在按预期方式调用,但从未显示我的statusDialog.如果通过按钮触发了相同的remoteCommand,则将显示statusDialog. JavaScript控制台中没有错误.

The refresh remoteCommand is being called as expected, but my statusDialog is never shown. If the same remoteCommand is triggered by a button click the statusDialog appears. There are no errors in JavaScript console.

为什么当RequestContext.execute()触发remoteCommand时,statusDialog为何不显示?如何显示它?我什至尝试将statusDialog.show()添加到execute(),但没有帮助.

Why is statusDialog not shown when remoteCommand is triggered by RequestContext.execute() and how can I make it appear? I even tried adding statusDialog.show() to execute() but it didnt help.

推荐答案

我知道了.解决方法如下:

I figured it out. Here is the solution:

<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()"/>

很显然,未显示状态对话框的原因是,在进行refresh()时,另一个Ajax调用完成并调用了statusDialog.hide().上面的JS代码维护着正在进行的Ajax调用次数的计数器,并且仅在所有调用完成后才隐藏状态对话框.现在按预期工作!

Apparently the reason why my status dialog was not being shown is that another Ajax call finished and called statusDialog.hide() while my refresh() thing was going on. The JS code above maintains a counter of how many Ajax calls are in progress, and will only hide the status dialog when all calls have finished. Works as intended now!

这篇关于在Primefaces RequestContext.execute()调用中无法显示对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆