【问题标题】:JSF2.0 - Handling erroneous Ajax calls with Primefaces 3.0JSF2.0 - 使用 Primefaces 3.0 处理错误的 Ajax 调用
【发布时间】:2012-02-06 21:48:30
【问题描述】:

我的 .xhtml 页面中有一个commandButton

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

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

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

任何帮助表示赞赏,谢谢。

【问题讨论】:

    标签: java ajax jsf jakarta-ee primefaces


    【解决方案1】:

    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

    【讨论】:

    • 感谢 StrekoZ 的回答。但我实际上是在寻找更深入的答案。我猜这是必须的。
    猜你喜欢
    • 2012-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 2013-07-03
    • 2015-09-26
    • 2013-08-15
    • 1970-01-01
    相关资源
    最近更新 更多