3

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

Mark Estrada
  • 9,013
  • 37
  • 119
  • 186
  • I am actually looking at this post by BalusC http://stackoverflow.com/questions/4523991/jsf-2-ajax-errors-not-displayed I thought they are similar in some ways. – Mark Estrada May 23 '12 at 09:17
  • You've also asked a releated question beforehand (which you never gave feedback on) http://stackoverflow.com/questions/10699327/linking-server-side-message-exception-with-ajax-request – BalusC May 23 '12 at 13:29
  • Sorry.. already replied to that. Thanks! – Mark Estrada May 25 '12 at 05:16

1 Answers1

2

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.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Ahh okay. Then how do you handle such case? Isn't there something that I could do with it? – Mark Estrada May 23 '12 at 08:11
  • I think that the way to go is using javax.faces.Message. You can send messages with various levels / styles of severity, including the error level – perissf May 23 '12 at 08:26
  • Thanks Matt.. Just a thought as I am a beginner in JSF in general. I have configured an error page in my web.xml. I was actually thinking that I would be forwarded to that page. Is this not the case for ajax request? – Mark Estrada May 23 '12 at 08:41
  • Also, whats the usual exception or error that would trigger the onerror handler at the client side to be called or the ajax status to be updated? I am thinking of scenario that would trigger an ajax request to result to an onerror situation. – Mark Estrada May 23 '12 at 08:43