Introduction
One of the holes in JSF, in my professional judgement, is the lack of really good exception handling on the client for AJAX exceptions. A number of client frameworks like PrimeFaces, OmniFaces, and RichFaces attempt to cleanup for this shortcoming, it is still a deficiency.The capabilities are present to make AJAX exception handling more robust. The "chemistry" is present in the framework, but it is not really standardized.
In this short example, I am demonstrating how to use the
jsf.ajax.addOnError
functionality to make client exception handling better. We will display at a minimum, an alert to let them know something bad has happened to their request.Additionally, I will demonstrate how to use XPath to get additional information from the response.
Solution
The solution is to add the following code to the<head />:
of the JSF page, or to an external JavaScript file that is included in the head. In my case, I am using an external JS file called jsf.ajax.handler.js
that is loaded using JSF <h:outputScript />
.
Here are the contents of the file.
References
- jsf.ajax
- Introduction to using XPath in JavaScript
- jsf.ajax.handler.js Gist on GitHub
No comments:
Post a Comment