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

标签 java ajax jsf jakarta-ee primefaces

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

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

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

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

感谢任何帮助,谢谢。

最佳答案

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

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

在 chrome 或 firebug 中尝试此代码。它将显示 xhr 对象

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

关于java - JSF2.0 - 使用 Primefaces 3.0 处理错误的 Ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8804020/

相关文章:

javascript - 使用 AJAX 从函数调用中填充 Select2

ajax - 三星互联网浏览器忽略 Ajax 请求中的 set-cookie

java - 对 JSF-Seam Web 应用程序页面进行 GZIP 的最佳方法是什么

java - 提交表单时未调用 JSF valuechangelistener

java - 如何通过Selenium从文本节点中提取文本?

java - 如何在一个crt文件中导出多个公共(public)证书

jquery - JSON 格式错误而 JSON 有效?

ajax - 当两个页面都包含在一个页面中时,如何从另一个页面的命令按钮更新一个页面中的Primefaces组件

Java - 循环问题

java - 如何将 java 代码嵌入到批处理脚本中?是否可以创建 .java/.bat 混合体?