4 Replies Latest reply on Jun 16, 2011 7:13 PM by Kumar Devarakonda

    Global error handling in my JSf-richfaces application

    rajesha Indurthi Newbie

      Iam trying to add a Global error page to my JSF -richfaces application. Iam trying to achieve it by adding the following elements to the web.xml.

      <error-page>
       <exception-type>java.lang.Throwable</exception-type>
       <location>/global/errorpage.jsp</location>
       </error-page>
       <error-page>
       <error-code>500</error-code>
       <location>/global/errorpage.jsp</location>
       </error-page>
       <error-page>
       <error-code>404</error-code>
       <location>/global/errorpage.jsp</location>
       </error-page>

      However when the application is actually throwing a run time exception or when it throws a 404 error, it is not being redirected to the error page as expected. Instead of the error page I just get a blank page. Is it possible that the rich faces filter is catching the errors, and so my application is not being able to be redirected to the error page when appropriate.

      How can I achive this behaviour in my jsf-richfaces application. Any help will be highly appreciated.

        • 1. Re: Global error handling in my JSf-richfaces application
          Nick Belaevski Master

          Hello,

          I've tried this and it worked ok. So a couple of questions for you:
          1. What is RF version used?
          2. Does the problem reproduce for AJAX or common server requests?

          • 2. Re: Global error handling in my JSf-richfaces application
            rajesha Indurthi Newbie

            Hi ,
            To answer your first question : Iam using richfaces 3.0 version.
            answer to the second question : Iam explicitly throwing a RuntimeException in my jsf application , to test that in the case of a runtime exception (unchecked exception) I should be redirected to the error page. I have included the code snippet below :

            throw new RuntimeException("Deliberately throwing the exception to test the global page" );


            Iam throwing the above exception explicitly in one of my managed beans, and am expecting that this exception will force a redirection to the errpage.

            My web.xml is as below :
            <filter-mapping>
            <filter-name>richfaces</filter-name>
            <servlet-name>Faces Servlet</servlet-name>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
            <dispatcher>INCLUDE</dispatcher>
            </filter-mapping>

            <servlet id="Servlet_1">
            <servlet-name>InitializationServlet</servlet-name>
            <servlet-class>com.equifax.aspire.infrastructure.kernel.web.InitializationServlet</servlet-class>
            <init-param id="InitParam_1">
            <param-name>initializationClasses</param-name>
            <param-value>com.equifax.ic.core.kernel.impl.InterConnectSystemInitializer</param-value>
            </init-param>
            <init-param id="InitParam_2">
            <param-name>requireCleanStart</param-name>
            <param-value>false</param-value>
            </init-param>
            <load-on-startup>5</load-on-startup>
            </servlet>
            <!-- Faces Servlet -->
            <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>6</load-on-startup>
            </servlet>

            <servlet-mapping id="ServletMapping_1">
            <servlet-name>InitializationServlet</servlet-name>
            <url-pattern>/initialization</url-pattern>
            </servlet-mapping>

            <!-- Faces Servlet Mapping -->
            <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.faces</url-pattern>
            </servlet-mapping>
            <welcome-file-list>
            <welcome-file>global/index.jsp</welcome-file>
            </welcome-file-list>
            <error-page>
            <exception-type>java.lang.Throwable</exception-type>
            <location>/global/errorpage.jsp</location>
            </error-page>
            <error-page>
            <error-code>500</error-code>
            <location>/global/errorpage.jsp</location>
            </error-page>
            <error-page>
            <error-code>404</error-code>
            <location>/global/errorpage.jsp</location>
            </error-page>


            As you can see I have my erro-page element defined after the rich faces filter and the coresponding mapping.

            Does this order in the web.xml matter? was you mapping (web.xml) just like mine .
            Iam using Sun RI of JSF in my application.

            I hope this will help you to see what is that you did different than me.Looking forward to hear back from you. Thanks in advance

            • 3. Re: Global error handling in my JSf-richfaces application
              Ilya Shaikovsky Master

              try to use latest versions at first. we can't support so old version like 3.0

              if you within JSF 1.2 environment I highly recommend to use 3.3.0 GA. In this case we could check for your issues more easily and you will be able to get updates because any changes and fixes do not backported to old versions.

              • 4. Re: Global error handling in my JSf-richfaces application
                Kumar Devarakonda Newbie

                Hi Ilya,

                If we have any error in backing beans (Managed Beans) or EJBs or jsps user is redirected to errorpage.jsp

                But the thing is we do not have the FacesContext object available there.

                Is there is any way I can get reference to the FacesContent in the errorpage.jsp

                 

                our web.xml looks as below:

                <error-page>

                    <exception-type>java.lang.Throwable</exception-type>

                    <location>/errorpage.jsp</location>

                  </error-page>

                 

                Thank you.