Mary Ryllo
Mary Ryllo

Reputation: 2371

Handling ajax errors with jsf.ajax.addOnError

How does jsf.ajax.addOnError actually catch errors? I didn't find any information about it's mechanism. I only found that it is a error listener.

Upvotes: 4

Views: 1824

Answers (1)

mabi
mabi

Reputation: 5306

Wherever you've found the statement that jsf.ajax.addOnError is an error-listener, that source is wrong. The addOnError function adds an error listener (ie, a function you define yourself and that gets called whenever the JSF framework encounters an error situation).

This is straight out of the JSF-2.2 spec, 13.3.6.2:

The jsf.ajax.addOnError function accepts a JavaScript function argument that will be notified when errors occur during any Ajax request/response cycle. [P1-start-event] The implementation must ensure the JavaScript function that is registered must be called in accordance with the errors outlined in Section TABLE 14-5 “Errors”.[P1-end]

Thus, the "errors" table defines under which conditions your function will get called. Here they are:

  • httpError: request status==null or request.status==undefined or request.status<200 or request.status >=300
  • serverError: The Ajax response contains an “error” element.
  • malformedXML: The Ajax response does not follow the proper format.
  • emptyResponse: There was no Ajax response from the server.

JSF implementations basically fire a Ajax request and define internal handlers that get called by the browser when a response arrives. Then, they are required to inspect the response and if one the above conditions are met, they look up if you have registered any functions to be called and execute them if need be (they do a lot more, but that's the part in question here).

Upvotes: 2

Related Questions