asyard
asyard

Reputation: 1743

handling exception messages in jsf

i have a servlet filter which controls if my web application is started normally;

public void doFilter(ServletRequest aReq, ServletResponse aResponse, FilterChain aChain) throws IOException, ServletException
    {
        HttpServletRequest request = (HttpServletRequest) aReq;
        HttpServletResponse response = (HttpServletResponse) aResponse;


        if(!myContext.isSystemReady())
        {
            // SHOW AN ERROR PAGE WITH SOME EXCEPTION MESSAGE
        }

        aChain.doFilter(request, aResponse);
        return;

    }

what is the best way to show error messages in this style?

how can i show it in my jsf page?

ERROR !<br />
detailed message is: <h:outputText value="errMsj HERE!"></h:outputText>

(using jsf2.0)

Upvotes: 0

Views: 1149

Answers (1)

lexicore
lexicore

Reputation: 43709

You can redirect to a specific error page by defining a web-app/error-page element in your web.xml:

<error-page>
  <error-code>500</error-code>
  <location>/error.xhtml</location>
</error-page>

Check the schema, there are more features (like reacting to specific exception classes).

Me peronally, I'd just throw an exception in doFilter (having full exception stack trace may be critical). The exception can later on be retrieved as #{requestScope['javax.servlet.error.exception']} if you want error page to be JSF page.

Upvotes: 1

Related Questions