Check the RichFaces developer guide chapter 5.10.1.
To execute your own code on the client in case of an error during Ajax request, it's necessary to redefine the standard "A4J.AJAX.onError" method:
A4J.AJAX.onError = function(req, status, message){
window.alert("Custom onError handler "+message);
}
The function defined this way accepts as parameters:
req
- a params string of a request that calls an error
status
- the number of an error returned by the server
message
- a default message for the given error
Thus, it's possible to create your own handler that is called on timeouts, internal server errors, and etc.
So, to display the server-generated error response, you'd like to do the following:
A4J.AJAX.onError = function(req, status, message){
document.open();
document.write(req.responseText);
document.close();
}
To redirect to the error page, do as follows:
A4J.AJAX.onError = function(req, status, message){
window.location = 'error.jsf';
}
You'll only need to pass mandatory error details as request parameter or let the server side store it in the session as Odelya suggested.
Related question: