简体   繁体   English

将Bean重定向到外部站点的JSF 1.2 IllegalState异常

[英]JSF 1.2 IllegalState Exception from backing bean redirect to external site

I am using a command button to post a form to backing bean method. 我正在使用命令按钮将表单发布到支持bean方法。 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. 由于重定向,我收到了IllegalState异常。

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: 这是支持bean方法中的问题代码:

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. 我意识到return语句是不必要的,不应到达,但是在填充redirectPage的情况下,这是必需的功能。 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? 显然,JSF不喜欢我跳出一个commandButton调用的方法,有什么想法可以解决此问题吗?

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! 我刚刚意识到了我的问题-我已经习惯于使用JSF的导航规则功能,以至于我完全忽略了这样一个事实:如果不打算使用导航规则,则不需要返回值! 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. 对我来说,最简单的解决方法是将commandButton操作设置为没有返回值且不受任何导航规则约束的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM