You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Marios Kerkemezos <ma...@yahoo.co.uk> on 2005/10/13 16:58:24 UTC

Exception Handling Blues...

Dear all,

I know this has been discussed before, but some issues
are still troubling me...

I’ve been experimenting with different methods for
handling exceptions in managed beans. The way I see
it, handling exceptions can be performed in the
following ways:


(A). Handling the exception internally, creating the
appropriate FacesMessages and / or forwarding to the
appropriate error page using the Navigation Handler.
This solution is obviously applicable only for
exceptions thrown in action methods and action
listeners.

(B). Wrapping the exception in a FacesException and
then re-throwing it. Doing so will cause the web
container (e.g. tomcat) to display the error page
configured in your web.xml. This is a fine solution
(for me at least!) for exceptions thrown elsewhere in
managed beans (e.g. in constructors that perform
initialization logic). However I discovered a slight
hitch: Internet Explorer has an "advanced" option
called "Show friendly HTTP error messages" enabled by
default, which will cause the Microsoft error page to
be displayed instead of the one configured in your
web.xml! This doesn’t seem to be an issue with Firefox
though...

(C).Catching the exception, and then explicitly
redirecting to some error page using
externalContext.redirect("...");
facesContext.responseComplete();  Again, this will
have more or less the same effect as the previous
solution, but this time avoiding the annoying IE
"feature".

I have tested all of the above solutions in a simple
MyFaces (ver. 1.1) application, and they all work
nicely. Turning to my real-world application, I am
currently using solution (a) (for my action methods
and listeners) but would also very much like to use
(c) as well (for everything else). However, I am also
using TilesServlet (from struts 1.1), and when tiles
are put in the picture bizarre things start to happen:

(Note the following applies only for exceptions thrown
anywhere in the bean BUT in action methods/listeners)

1) Using solution (c) will cause the page that was
originally requested to be displayed (possibly
incomplete), but the redirect call is definitely being
ignored (!). 

2) Using solution (b) will produce a white page with a
single line printed: 

[ServletException in:/WEB-INF/tiles/layout.jsp] Cannot
get value for expression
'#{someBean.someRandomProperty}''. 

The exception seems to be "consumed" at some unknown
point and never "bubbles up" to the web container
(although it is still printed in the application
context log). I also tried catching the exception by
setting up an http filter, but again without success
(again no exception is caught by the filter).

Since there are a lot of people using MyFaces and
Tiles together someone must have dealt with this
before. If anyone can help out, I would greatly
appreciate it. I will provide code samples if
necessary.

If you are still reading, thank you for your patience!

Mario



		
___________________________________________________________ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com

Re: Exception Handling Blues...

Posted by Martin Marinschek <ma...@gmail.com>.
Do you use the MyFaces Tiles integration? with the MyFaces Tiles-ViewHandler?

regards,

Martin

On 10/13/05, Marios Kerkemezos <ma...@yahoo.co.uk> wrote:
> Dear all,
>
> I know this has been discussed before, but some issues
> are still troubling me...
>
> I've been experimenting with different methods for
> handling exceptions in managed beans. The way I see
> it, handling exceptions can be performed in the
> following ways:
>
>
> (A). Handling the exception internally, creating the
> appropriate FacesMessages and / or forwarding to the
> appropriate error page using the Navigation Handler.
> This solution is obviously applicable only for
> exceptions thrown in action methods and action
> listeners.
>
> (B). Wrapping the exception in a FacesException and
> then re-throwing it. Doing so will cause the web
> container (e.g. tomcat) to display the error page
> configured in your web.xml. This is a fine solution
> (for me at least!) for exceptions thrown elsewhere in
> managed beans (e.g. in constructors that perform
> initialization logic). However I discovered a slight
> hitch: Internet Explorer has an "advanced" option
> called "Show friendly HTTP error messages" enabled by
> default, which will cause the Microsoft error page to
> be displayed instead of the one configured in your
> web.xml! This doesn't seem to be an issue with Firefox
> though...
>
> (C).Catching the exception, and then explicitly
> redirecting to some error page using
> externalContext.redirect("...");
> facesContext.responseComplete();  Again, this will
> have more or less the same effect as the previous
> solution, but this time avoiding the annoying IE
> "feature".
>
> I have tested all of the above solutions in a simple
> MyFaces (ver. 1.1) application, and they all work
> nicely. Turning to my real-world application, I am
> currently using solution (a) (for my action methods
> and listeners) but would also very much like to use
> (c) as well (for everything else). However, I am also
> using TilesServlet (from struts 1.1), and when tiles
> are put in the picture bizarre things start to happen:
>
> (Note the following applies only for exceptions thrown
> anywhere in the bean BUT in action methods/listeners)
>
> 1) Using solution (c) will cause the page that was
> originally requested to be displayed (possibly
> incomplete), but the redirect call is definitely being
> ignored (!).
>
> 2) Using solution (b) will produce a white page with a
> single line printed:
>
> [ServletException in:/WEB-INF/tiles/layout.jsp] Cannot
> get value for expression
> '#{someBean.someRandomProperty}''.
>
> The exception seems to be "consumed" at some unknown
> point and never "bubbles up" to the web container
> (although it is still printed in the application
> context log). I also tried catching the exception by
> setting up an http filter, but again without success
> (again no exception is caught by the filter).
>
> Since there are a lot of people using MyFaces and
> Tiles together someone must have dealt with this
> before. If anyone can help out, I would greatly
> appreciate it. I will provide code samples if
> necessary.
>
> If you are still reading, thank you for your patience!
>
> Mario
>
>
>
>
> ___________________________________________________________
> How much free photo storage do you get? Store your holiday
> snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
>
>


--

http://www.irian.at
Your JSF powerhouse -
JSF Trainings in English and German