Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF PostConstruct Exception Handling - Redirect

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?

like image 687
monkey-wrench Avatar asked Jun 13 '26 08:06

monkey-wrench


1 Answers

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

like image 109
damian Avatar answered Jun 18 '26 01:06

damian