javajsfjakarta-eejsf-1.2mojarra

How to swallow an exception in JSF 1.2/Mojarra


The ViewExpiredException is being handled by a redirect to the login screen. The problem is that the exception is still logged, and the customer would strongly like to have the server.log exception-free.

While it may be a questionable requirement in this case, I still have to make it happen. We use Mojarra and deploy on JBoss EAP 5.1

The MyFaces approach does not help as I obviously cannot wrap the MyFacesServlet using Mojarra

I could not apply the advice given in the JBoss JSF guide to wrap the Faces servlet as I cannot find the jsf-integration-deployer-jboss-beans.xml anywhere.

I cannot get the approach proposed by Ed Burns to work either. I guess the reason is that it is targeted at JSF2 for I cannot find the javax.faces.context.ExceptionHandlerFactory in my jars.

Making the matter worse, I am quite new to JSF, so I have to rely on detailed guidance, in search of which I have found the above approaches but failed to apply them.

Thank you


Solution

  • That article is indeed targeted on JSF 2.x. JSF 1.x does not have any exception handling facility.

    Just catch and redirect yourself instead of letting the container do. A filter is a sensible place for this:

    try {
        chain.doFilter(request, response);
    } catch (ServletException e) {
        if (e.getRootCause() instanceof ViewExpiredException) {
            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (HttpServletResponse) response;
            res.sendRedirect(req.getContextPath() + "/errors/session-expired.jsf");
        } else {
            throw e;
        }
    }
    

    Map this in web.xml on the servlet name of the FacesServlet to get it to run.