简体   繁体   English

JSF2.0 - 使用Primefaces 3.0处理错误的Ajax调用

[英]JSF2.0 - Handling erroneous Ajax calls with Primefaces 3.0

I have a commandButton in my .xhtml page: 我的.xhtml页面中有一个commandButton

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

It's simply making an Ajax call. 它只是在进行Ajax调用。 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? 如何在Ajax调用过程中检测互联网连接问题(客户端/浏览器),超时,会话超时,服务器端异常,崩溃等情况,以便向用户显示信息性消息?

Does the onerror attribute of p:ajax handle all of those? p:ajaxonerror属性是否处理所有这些? If not, then what? 如果没有,那又怎样? :) What's the default timeout btw? :)什么是默认超时btw?

Any help appreciated, thanks. 任何帮助表示感谢,谢谢。

onerror calls this function: onerror调用此函数:
onerror(xhr, status, exception) - Javascript callback to process when ajax request fails. onerror(xhr,status,exception) - 当ajax请求失败时要处理的Javascript回调。 Takes three arguments, xmlhttprequest, status string and exception thrown if any. 采用三个参数,xmlhttprequest,状态字符串和抛出的异常(如果有的话)。
This info is from documentation. 此信息来自文档。 xhr - is actually a request. xhr - 实际上是一个请求。 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>

Try this code in chrome or firebug. 在chrome或firebug中尝试此代码。 It will show xhr object 它将显示xhr对象

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM