hello,

additional information:

if you would like to handle exceptions which occurred during the "invoke
application" phase, there's a simple solution:
use an application action listener

in addition:
you can use aop to handle exceptions (e.g. have a look at the aop support of
spring).

regards,
gerhard



2008/6/4 Kuhn, Harald <[EMAIL PROTECTED]>:

> Hi,
>
> I struckled with the same problems (definition of JSF error pages in
> web.xml).
> On further debugging I realized that the problem lies in the postback
> handling of JSF:
>
> Lets say a postback zu View a.xhtml causes any error in some backing
> bean.
> Then the flow is as followed:
>
> 1) JSF Lifecyle of view a.xhtml starts
> 2) Exception is thrown (i.e. during InvokeApplication)
> 3) if no JSF error handlers are defined this exception pops up to tomcat
> (Servlet-API) error handling
> 4) tomcat searches for error page in web.xml
> 5) tomcat forwards to the error-page
> 6) as the error page is also JSF, the JSF lifecycle for the error page
> is started
> 7) In Phase RestoreView JSF checks if it is a postback
>        As it is just a forward it is the same request as for 1)
>        Therefore there is a postback token on the request and the view
> corresponding to this token is restored.
>        As this token is from the inital request/postback of view
> a.xhtml, this view is restored.
> 8) as the JSF lifecycle continoues with view a.xhtml the exception is
> reached a second time
> 9) as there are errors during error-handling, tomcat shows the standard
> stacktrace.
>
> A solution that worked for our requirement is:
>
> a) Create a custom FACES-Servlet that implements interface
> DelegatedFacesServlet and delegates to the original FacesServlet
> b) Register this servlet in your web.xml
>
> The error handling works like this:
> 1) Catch all exception in the service-Method of the servlet
> 2) store the exception inside a session bean (or maybe page-flow is
> sufficent as well)
> 3) redirect to error page
> 4) error page is loaded by browser and displays the stored exception
> from session bean.
>
> In this solution the error page is loaded by the browser and therefore
> it is an initial request and no postback any more.
>
> Hope this helps
>
>  Harald
>
>
> -----Original Message-----
> From: haric [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 03, 2008 7:11 PM
> To: [email protected]
> Subject: Handling Server Errors
>
>
>
> I am trying to write my own exception handler as per the details at
> http://wiki.apache.org/myfaces/Handling_Server_Errors
>
> I tried to override handleException(fc,ex) method as following
> public void handleException(FacesContext fc, Exception ex) throws
> Throwable
> {
>        log.error("Exception occured...", ex);
>        if(ex is of sometype){
>                NavigationHandler nh =
> fc.getApplication().getNavigationHandler();
>                nh.handleNavigation(fc, null, "exceptionNavigation");
>                fc.renderResponse();
>        } else {
>                throw ex;
>        }
> }
>
> in web.xml
> ----------
> <error-page>
>  <error-code>500</error-code>
>  <location>/errorDisplay.xhtml</location>
> </error-page>
>
> navigation rule
> --------------
> <navigation-rule>
>  <navigation-case>
>  <from-outcome>exceptionNavigation</from-outcome>
>  <to-view-id>/errorPages/errorHtml.html</to-view-id>
>  </navigation-case>
> </navigation-rule>
>
> The handleException() method gets invoked but never redirects to
> errorHtml.html for if case, and it also fails for else case. If I get
> the
> error 500 and as per web.xml it should redirect errorDisplay.xhtml
> instead
> it shows whole stack trace on the web page.
>
> The functionality I am looking is:
> - Catch the exception in handleException() method
> - log the error
> - If error is certain type redirect to static html/jsf page using
> navigation
> handler
> - else throw the exception
> - handle 500/404 and other exceptions using web.xml error pages
> configuration
> - if possible populate a bean with error messages or add messages to
> FacesContext and redirect a standard jsf file where we display
> <h:messages>
>
>
> I appreciate help on this.
> --
> View this message in context:
> http://www.nabble.com/Handling-Server-Errors-tp17628641p17628641.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Reply via email to