How to handle code error 500 in Richfaces

I am using Richfaces 3.2.2 and should show the user a 500 error page when there is an Exception. The problem is that when I use the ajax event, I cannot show the user 500 error when there is an Exception. I already defined the error page in web.xml.

Sorry my english. Any suggestion please?

+3
source share
2 answers

Since you are probably using JSF1.2 rather than JSF2, you can use FaceletViewHandlerto handle exceptions.

public class CustomViewHandler extends FaceletViewHandler {
    ...
    @Override
    protected void handleRenderException(FacesContext context, Exception ex) throws IOException, ELException,
        FacesException {
        try {
            ..

            getSessionMap().put("GLOBAL_ERROR", ex);
            getHttpResponseObject().sendRedirect("/error.jsf");
        } catch (IOException e) {
            log.fatal("Couldn't redirect to error page", e);
        }
    }
}

of course you need to handle it in a bean, just catch the exception from the session:

Throwable ex = (Exception) getSessionMap().remove("GLOBAL_ERROR");
+2
source

RichFaces 5.10.1.

5.10.1

Ajax, A4J.AJAX.onError:

A4J.AJAX.onError = function(req, status, message){
    window.alert("Custom onError handler "+message);
}

, , :

  • req - ,
  • status - ,
  • message -

, , -, ..

, , :

A4J.AJAX.onError = function(req, status, message){
    document.open();
    document.write(req.responseText);
    document.close();
}

, :

A4J.AJAX.onError = function(req, status, message){
    window.location = 'error.jsf';
}

, .

:

+4

Source: https://habr.com/ru/post/1757152/


All Articles