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?
JSF PostConstruct Exception Handling - Redirect
Asked Answered
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. –
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.