问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/6208037/jsf-postconstruct-exception-handling-redirect