无法在JSF 2应用程序上捕获ajax错误

时间:2012-05-23 07:25:00

标签: ajax jsf-2 primefaces

我碰巧不明白为什么我不能在p上发出警报:ajaxStatus应该发生异常

我基本上在facelet页面中有这段代码

<p:ajaxStatus onerror="alert('Error occurred!')" />

<p:commandLink  title="Delete" process="@this" 
    actionListener="#{myBean.deleteData}">
    <h:outputText value="Delete" />                 
</p:commandLink>

在我的bean上,我提出了一个异常只是为了测试ajax状态

public void deleteData(ActionEvent event) {
    throw new CustomException("Testing");
}

我不确定,但是没有在ajax请求上触发警报。

我检查了萤火虫并看到了这个ajax响应。

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="javax.faces.ViewState"><![CDATA[5240489117331224423:7642972336085906948]]></update></changes></partial-response>

但是当我检查服务器日志时,我看到了这个注册的

javax.faces.event.AbortProcessingException: /pages/members.xhtml @208,128 actionListener="#{myBean.deleteData}": com.test.CustomException: Testing

为什么会这样?

Primefaces 3.2 / Glassfish / JSF 2.0

1 个答案:

答案 0 :(得分:2)

来自p:ajaxStatus的Primefaces 3.2文档:

onerror: Client side callback to execute when an ajax request fails.

在Firebug中,您会获得常规的ajax响应。所以请求没有失败。从我的理解失败意味着没有或无效的回应。你看到的是预期的行为。

更新:由perissf评论,通常的方法是在您的操作方法中生成FacesMessage并使用您的ajax请求更新h:messages标记。