JSF PostConstruct Exception Handling - Redirect
Asked Answered
G

1

3

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?

Geoff answered 1/6, 2011 at 21:38 Comment(0)
A
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

Agential answered 17/10, 2011 at 14:29 Comment(2)
The key aspect that this doesn't cover is that it still tries to process the entire bean.Geoff
@Geoff 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?Agential

© 2022 - 2024 — McMap. All rights reserved.