For regular queries, we can simply register <error-page> in web.xml . However, this does not apply to Ajax requests. By default, errors during an Ajax request will result in a small pop-up window in the browser that shows an exception.
The main example I'm struggling with is the uniform handling of ViewExpiredException . For standard queries, I redirect to a page that explains that the user is not logged in and provides a link to the login page. I would like to do the same for Ajax requests. There seem to be several ways:
- I could write a javascript function that handles the error on the client side and redirects it to the error page. Then I would have to add this function every
<f:ajax> -tag on all pages using the onerror attribute. Is there any way to tell JSF that I want this javascript function to be the default error handler for all <f:ajax> -tags? - I could use my own exception handler as described in this blog . I seem to be doing what I want, but I wonder if this is too much. Is there a simpler solution?
So my question is: how should this be resolved? Which of the approaches listed by me should be used? Is there any other approach that I don't know about?
source share