JSF2.0 - 使用 Primefaces 3.0 处理错误的 Ajax 调用 [英] JSF2.0 - Handling erroneous Ajax calls with Primefaces 3.0

查看:24
本文介绍了JSF2.0 - 使用 Primefaces 3.0 处理错误的 Ajax 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .xhtml 页面中有一个 commandButton:

I have a commandButton in my .xhtml page:

<p:commandButton action="#{someone.doSomething()}"
                ajax="true"
                onerror="errorDialog.show();">
</p:commandButton>

它只是进行 Ajax 调用.如何在 Ajax 调用过程中检测诸如 Internet 连接问题(客户端/浏览器的)、超时、会话超时、服务器端异常、崩溃等情况,以便向用户显示信息性消息?

It's simply making an Ajax call. How can I detect situations such as internet connection problem (of the client/browser), timeout, session-timeout, server-side exceptions, crashes etc in the middle of an Ajax call so as to show an informative message to the user?

p:ajaxonerror 属性是否处理所有这些?如果不是,那又怎样?:)顺便说一句,默认超时是多少?

Does the onerror attribute of p:ajax handle all of those? If not, then what? :) What's the default timeout btw?

感谢任何帮助,谢谢.

推荐答案

onerror 调用此函数:
onerror(xhr, status, exception) - ajax 请求失败时处理的 Javascript 回调.接受三个参数,xmlhttprequest、状态字符串和抛出的异常(如果有).
此信息来自文档.xhr - 实际上是一个请求.因此可以找到请求状态和许多其他信息.

onerror calls this function:
onerror(xhr, status, exception) - Javascript callback to process when ajax request fails. Takes three arguments, xmlhttprequest, status string and exception thrown if any.
This info is from documentation. xhr - is actually a request. So there can be found request status and a lot of other info.

<p:commandButton action="#{someone.doSomething()}"
            ajax="true"
            onerror="console.debug(xhr)">
</p:commandButton>

在 chrome 或 firebug 中试试这个代码.它将显示 xhr 对象

Try this code in chrome or firebug. It will show xhr object

查看http://primefaces.googlecode.com/files/primefaces_users_guide_3_0.pdf 7.2 节 Ajax API

Get a look into http://primefaces.googlecode.com/files/primefaces_users_guide_3_0.pdf section 7.2 Ajax API

这篇关于JSF2.0 - 使用 Primefaces 3.0 处理错误的 Ajax 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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