I am using a command button to post a form to backing bean method. At the end of that method I am attempting to redirect to an external site after setting various options in the response. I get an IllegalState Exception because of the redirect.
at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendRedirectWithStatusCode(WebAppDispatcherContext.java:571)
at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendRedirect(WebAppDispatcherContext.java:528)
at com.ibm.ws.webcontainer.srt.SRTServletResponse.sendRedirect(SRTServletResponse.java:1234)
at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:426)
at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:181)
here is the problem code from the backing bean method:
if ( redirectPage != null ) {
logger.debug("attempting redirect: " + redirectPage);
try {
getFacesContext().getExternalContext().redirect(redirectPage);
FacesContext.getCurrentInstance().responseComplete();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
return result;
I realize that the return statement is unnecessary and should not be reached, but in the case of this redirectPage getting populated this is required functionality. I can't use navigation rules to setup a dynamic external site redirect, right? What can I do?
looking closer at the exception, it seems the navigation handler is causing the problem. Apparently JSF does not like me jumping out a method called by a commandButton, any ideas how to work around this?
I just realized my problem - I am so used to using the navigation rule feature of JSF that I completely overlooked the fact that a return value is unnecessary if not going to use navigation rules! The exception was telling me it was a problem with navigation but I was not seeing it.
The simple fix was for me to have the commandButton action set to a method that had no return value and was not tied to any navigation rules.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.