I'd like to handle a JSF @PostConstruct exception by redirecting to another page. I'm using FacesContext.getCurrentInstance().getExternalContext().dispatch("page.jsf");
which works great but since the page uses 2 backing beans it continues to load the other backing bean (and if it encounters an error on the other backing bean it never gets to that dispatch/redirect). My question is.. is there a way to force that dispatch to happen right away and not load everything else?
Asked
Active
Viewed 5,428 times
3

monkey-wrench
- 1,556
- 2
- 14
- 16
1 Answers
4
Look at this similar question: JSF navigation redirect to previous page
According to BalusC you can use the following instead of dispatch:
FacesContext.getCurrentInstance().getExternalContext().redirect(url);
Or, in order to stop rendering the current page, put
FacesContext.getCurrentInstance().responseComplete();
Regards
-
The key aspect that this doesn't cover is that it still tries to process the entire bean. – monkey-wrench Feb 06 '12 at 16:23
-
@monkey-wrench What do you mean by 'tries to process the entire bean'?. if you add a return statement after the redirect then the postconstruct method will end, are you talking about this? – damian Feb 22 '12 at 12:25