如何显示ajaxstatus动态Primefaces组件 [英] How to show ajaxstatus for dynamic Primefaces components

查看:731
本文介绍了如何显示ajaxstatus动态Primefaces组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到,pretty的多所有PF组件具有动态属性设置为真将只是一个短暂的延迟(这是可以理解)之后出现,也不会触发AJAX启动/停止事件

这是我的(完美的工作),阿贾克斯状态组件,实际对话内容不再赘述:

 <电话号码:ajaxStatus的OnStart =statusDialog.show();的onSuccess =statusDialog.hide();的onerror =errorDialog.show();/>
 

这是一个动态加载的对话框。它需要从支持bean中获取数据:

 <电话号码:对话模式=真widgetVar =confDialog位置=中心ID =confD动态=真正的>
<电话号码:panelGrid的>
<电话号码:行>
    <电话号码:柱>
        < H:的outputText值=日期>< / H:的outputText>
    < / P:列>
    <电话号码:柱>
        < H:的outputText值=#{myBean.currentDate}>
            < F:convertDateTime区域设置=#{myBean.currentLanguage}类型=既有DATESTYLE =满timeStyle =满的timeZone =#{myBean.currentTimeZone}>< / F:convertDateTime>
        < / H:的outputText>
    < / P:列>
< / P:行>
< / P:panelGrid的>
<电话号码:的commandButton值=关闭类型=按钮的onclick =confDialog.hide();>
< / P:的commandButton>
< / P:对话框>
 

有一个命令,做的东西,并显示动态加载的确认对话框:

 <电话号码:的commandButton值=做类型=提交阿贾克斯=真的过程=@表
                行动=#{bean.processForm}
                的onComplete =如果(args.validationFailed!){confDialog.show();}
                更新=confD @form/>
 

显示阿贾克斯状态对话框,而命令提交数据,以支持bean并获取数据了。然后AJAX状态对话框消失,有1-2秒的延迟,并示确认对话框。

同样的情况与动态加载标签(在PF TabView的组成部分)。

为什么在动态组件负载不显示我的AJAX状态对话框?我怎样才能显示它?

编辑:

由于@partlov我想出了一个解决方案,无需重写PF功能,加入JQ AJAX启动/停止处理程序来动态加载的对话框:

  jQuery的(文件)。就绪(函数(){
 confDialog.getJQ()ajaxStart(函数(){statusDialog.show()})。
 confDialog.getJQ()ajaxStop(函数(){statusDialog.hide()})。
});
 

解决方案

写在Primefaces文档<电话号码:ajaxStatus> 只是拦截全局AJAX请求,而该请求是不是全球性的。有没有简单的方法你想要做到这一点。由于装载的对话时间短我实在看不出一点这一点。唯一的解决办法,因为我认为,是重载Primefaces对话框JavaScript方法。

Primefaces调用 loadContents()时,对话框的内容加载,所以你可以重写此方法此方法。我不建议你这样做,因为这是无证,可以在Primefaces的未来版本中进行更改:

  jQuery的(文件)。就绪(函数(){
  VAR oldLoadContents = PrimeFaces.w​​idget.Dialog.loadContents;
  PrimeFaces.w​​idget.Dialog.loadContents =功能(){
    statusDialog.show();
    oldLoadContents();
  }
});
 

这应该表明你对动态加载对话框。您可以使用 OnShow中 点属性:对话框来关闭对话框:

  OnShow中=statusDialog.hide()
 

I have noticed that pretty much all PF components that have 'dynamic' attribute set to 'true' will only show up after a short delay (which is understandable), and also will not trigger ajax start/stop event.

This is my (perfectly working) Ajax status component, actual dialog contents omitted for brevity:

<p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();" onerror="errorDialog.show();"/> 

This is a dynamically loaded dialog. It needs to get data from backing beans:

<p:dialog modal="true" widgetVar="confDialog" position="center" id="confD" dynamic="true">
<p:panelGrid>
<p:row>
    <p:column>
        <h:outputText value="Date"></h:outputText>
    </p:column>
    <p:column>
        <h:outputText value="#{myBean.currentDate}">
            <f:convertDateTime locale="#{myBean.currentLanguage}" type="both" dateStyle="full" timeStyle="full" timeZone="#{myBean.currentTimeZone}"></f:convertDateTime>
        </h:outputText>
    </p:column>
</p:row>
</p:panelGrid>
<p:commandButton value="Close" type="button" onclick="confDialog.hide();">
</p:commandButton>
</p:dialog>

A commandbutton that does something and displays dynamically loaded confirmation dialog:

<p:commandButton value="Do it" type="submit" ajax="true" process="@form"
                action="#{bean.processForm}"
                oncomplete="if(!args.validationFailed){confDialog.show();}"
                update="confD @form"/>

Ajax status dialog is displayed while the commandbutton submits the data to backing bean and gets data back. Then ajax status dialog disappears, there is a delay of 1-2 seconds, and confirmation dialog is shown.

The same happens with dynamically loaded tabs (in PF tabView component).

Why isn't my ajax status dialog displayed during dynamic component load? How can I show it?

EDIT:

thanks to @partlov I figured out a solution without overriding PF function, by adding JQ ajax start/stop handler to the dynamically loaded dialog:

jQuery(document).ready(function() {
 confDialog.getJQ().ajaxStart(function(){statusDialog.show()});
 confDialog.getJQ().ajaxStop(function(){statusDialog.hide()});
});

解决方案

As written in Primefaces documentation <p:ajaxStatus> just intercepts global AJAX requests, and this request is not global. There is no easy way to do this what you want. As time of loading of dialog is short I really don't see point for this. Only solution, as I think, is to overload Primefaces dialog JavaScript methods.

Primefaces calls loadContents() method when dialog content is loaded so you can override this method for this. I don't advice you to do that, because this is undocumented and can be changed in future versions of Primefaces:

jQuery(document).ready(function() {
  var oldLoadContents = PrimeFaces.widget.Dialog.loadContents;
  PrimeFaces.widget.Dialog.loadContents = function() {
    statusDialog.show();
    oldLoadContents();
  }
});

This should show your dialog on dynamic loading. You can use onShow attribute of p:dialog to close your dialog:

onShow="statusDialog.hide()"

这篇关于如何显示ajaxstatus动态Primefaces组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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