webtier@glassfish.java.net

Re: [webtier] error page in jsf

From: Jan-Kees van Andel <jankeesvanandel_at_gmail.com>
Date: Wed, 1 Oct 2008 21:14:03 +0200

Well, I don't like to do any error handling or navigation inside managed
beans, but if you insist, you can grab the NavigationHandler via the
FacesContext and call it directly. Don't forget to call
FacesContext.responseComplete() afterwards to short circuit the lifecycle,
like this.

try {
  // Some data access code here
} catch (SQLException e) {
  FacesCOntext fc = FacesCOntext.getCurrentInstance();
  fc.getApplication().getNavigationHandler().handleNavigation(fc,
"#{bean.actionName}", "toErrorPage");
  fc.responseComplete();
}

And the faces-config.xml:

<navigation-rule>
  <navigation-case>
    <from-outcome>toErrorPage</from-outcome>
    <to-view-id>/errorPage.xhtml</to-view-id>
    <redirect />
  </navigation-case>
</navigation-rule>

If you don't want to use a redirect, for example, if you would like to
display some error data inside the error page, you need to make two changes.
The first is obvious, remove the <redirect />. The second one is replace
fc.responseComplete() to fc.renderResponse().

I think both options should work fine.

But again, the managed bean is not the right place for default error
handling or navigation. Managed beans probably get large and ugly when you
do these kind of things often.

Regards,

Jan-Kees


2008/10/1 <webtier_at_javadesktop.org>

> hello all
>
> i programmed an datatable in jsf , it calls via a managedbean these
> procedure :
> public Result getAll() throws SQLException
>
> when these page generates an sqlerror i got an internal error 500, is there
> a way to redirect to an error page in the managedbean ?
>
> thanks all
> [Message sent by forum member 'xsi' (xsi)]
>
> http://forums.java.net/jive/thread.jspa?messageID=302748
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>
>