Mark Estrada
Mark Estrada

Reputation: 9191

Unable to catch ajax error on JSF 2 App

I happen not to understand this why I cannot get an alert on a p:ajaxStatus should an exception has occurred

I basically have this code in a facelet page

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

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

On my bean, I raised an exception just to test the ajax status

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

I am not sure but the alert is not triggered on ajax request.

I checked firebug and saw this ajax response.

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

But when I checked the server log I saw this registered

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

Why is this so?

Primefaces 3.2/Glassfish/JSF 2.0

Upvotes: 3

Views: 1965

Answers (1)

Matt Handy
Matt Handy

Reputation: 30025

From the Primefaces 3.2 documentation of p:ajaxStatus:

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

In Firebug you get a regular ajax response. So the request did not fail. From my understanding failure means that there is either no or an invalid response. What you see is the expected behavior.

Update: As commented by perissf, the usual way would be to generate a FacesMessage in your action method and update an h:messages tag with your ajax request.

Upvotes: 2

Related Questions