myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heath Borders <heath.bord...@gmail.com>
Subject Re: Error handling & redirecting from BB constructor possible ?
Date Tue, 07 Dec 2004 00:57:10 GMT
We use the second method as our catch-all.  I would say that a
redirect within the web.xml is better because its one point of
accountability for all your classes.


On Mon, 6 Dec 2004 19:46:56 -0500, cote.mark@hydro.qc.ca
<cote.mark@hydro.qc.ca> wrote:
> 
> 
> 
> I tried the second option, and it doesn't seem to work either...:) 
> I created a specific exception which is thrown from the constructor of the 
> backing bean and mapped it in web.xml to an error page. 
> 
> Do you think tiles may have something to do with it ? 
> This is part of my entry in tiles-defs: 
> 
> <definition name="/erreurGenerique.tiles" extends="rootLayout"> 
> ..... 
> </definition> 
> 
> And this is from my web.xml 
> 
>  <error-page> 
>        
> <exception-type>com.hydroquebec.lsw.ExceptionErreurGenerique</exception-type>
>         <location>/erreurGenerique.jsp</location> 
>  </error-page> 
> 
> (I know there is a diff between the *.tiles and *jsp suffixes, but I believe
> the mapping is done via the JspTilesViewHandlerImpl view handler)
> 
> My context root is "lsw". I've tried every variation possible for the path 
> in the location tag: 
> 
> /erreurGenerique.jsp 
> /faces/erreurGenerique.jsp 
> /lsw/faces/erreurGenerique.jsp 
> etc.... 
> 
> and it simply wont't catch. 
> 
> 
> Could anyone give me example of a Backing Bean constructor that loads info 
> from a database and contains code which redirects a user to an 
> error page should the database link be broken ? 
> 
> Thanks in advance, 
> 
> 
> 
> Mark 
> 
> 
> -----Message d'origine----- 
> De : Heath Borders [mailto:heath.borders@gmail.com] 
> Envoyé : vendredi 3 décembre 2004 15:07 
> À : MyFaces Discussion 
> Objet : Re: Error handling & redirecting from BB constructor possible ? 
> 
> Well, this should work.  Look at the JSF 1.1 API for further details, but
> here are some things that could be going wrong:
> 
> 1. FacesContext.getCurrentInstance().getExternalContext().redirect(String) 
> already called FacesContext.responseComplete(), so you don't need to call
> FacesContext.renderResponse(), though this shouldn't matter 2.
> FacesContext.getCurrentInstance().getExternalContext().redirect(String)
> 
> needs the absolute URI you are redirecting to.  If you provide the wrong
> URI, I don't know what will happen. 
> 
> If you're still dead set against using 
> FacesContext.getCurrentInstance().getExternalContext().redirect(String) 
> you could just set up an error page in your web.xml for the exception,
> though this may not be optimal. 
> 
> 
> On Fri, 3 Dec 2004 14:48:07 -0500, cote.mark@hydro.qc.ca
> <cote.mark@hydro.qc.ca> wrote: 
> > 
> > 
> > Heath, 
> > 
> > I tried this also (but forgot to mention), followed by 
> > "FacesContext.getCurrentInstance().responseComplete()" 
> > but the request keeps processing the same jsp & the redirect never
> happens. 
> > 
> > Is there any other way to handle errors inside BB constructor ? 
> > In other words, I would expect most apps to have to deal with this... 
> > 
> > 
> > 
> > 
> > 
> > -----Message d'origine----- 
> > De : Heath Borders [mailto:heath.borders@gmail.com] Envoyé : vendredi 
> > 3 décembre 2004 14:22 À : MyFaces Discussion Objet : Re: Error 
> > handling & redirecting from BB constructor possible ? 
> > 
> > 
> > 
> > Call 
> > FacesContext.getCurrentInstance().getExternalContext().redirect(String 
> > ) 
> > 
> > 
> > On Fri, 3 Dec 2004 13:24:13 -0500, cote.mark@hydro.qc.ca 
> > <cote.mark@hydro.qc.ca> wrote: 
> > > 
> > > Does anybody know how to go about redirecting to an error page from 
> > > the constructor of a backing bean. 
> > >  
> > > For example: 
> > >  
> > > class BBean 
> > > { 
> > >      Data someData; 
> > >      
> > >      public BBean () 
> > >      { 
> > >            try 
> > >            { 
> > >             someData = getData(); 
> > >            } 
> > >            catch(Throwable t) 
> > >            { 
> > >             // What is the code here to redirect to an error page ? 
> > >            } 
> > >      } 
> > >      
> > >      .... 
> > > } 
> > >  
> > > I tried using 
> > > FacesContext.getCurrentInstance().getExternalContext().dispatch("err 
> > > or .jsp"); but I got a response already rendered error. 
> > >  
> > > Thanks 
> > >  
> > > Mark 
> > 
> > 
> > -- 
> > If you don't have a GMail account, I probably have 5 invites.  Just ask! 
> > -Heath Borders-Wing 
> > hborders@mail.win.org 
> 
> 
> -- 
> If you don't have a GMail account, I probably have 5 invites.  Just ask! 
> -Heath Borders-Wing 
> hborders@mail.win.org 


-- 
If you don't have a GMail account, I probably have 5 invites.  Just ask!
-Heath Borders-Wing
hborders@mail.win.org

Mime
View raw message