Jsf 2 JSF2.0重定向错误
从preRenderView事件重定向时,我收到一个非法状态异常。我只是通过引入例外情况来解决这个问题。有没有更干净的方法来达到同样的效果Jsf 2 JSF2.0重定向错误,jsf-2,Jsf 2,从preRenderView事件重定向时,我收到一个非法状态异常。我只是通过引入例外情况来解决这个问题。有没有更干净的方法来达到同样的效果 @Named @RequestScoped public class LogoutBean implements Serializable { public void preRenderView(ComponentSystemEvent e) { userSessionBean.logout(); FacesC
@Named
@RequestScoped
public class LogoutBean implements Serializable
{
public void preRenderView(ComponentSystemEvent e)
{
userSessionBean.logout();
FacesContext ctx = FacesContext.getCurrentInstance();
try
{
ctx.getApplication().getNavigationHandler().handleNavigation(ctx, null, "/pages/index?faces-redirect=true");
}
catch (IllegalStateException exc)
{
// Ignore. This exception is caused by redirecting after the response is already committed. The redirect works anyway.
}
}
@Inject
private UserSessionBean userSessionBean;
}
我建议改为发送重定向
FacesContext.getCurrentInstance.responseComplete;没有效果。我对第二个选项有点不舒服,因为我失去了视图ID抽象。嗯,哦,当然没有效果。您已经进入渲染响应阶段!我编辑了答案以删除该建议。另一个问题是,我正在使用UrlRewriteFilter,而显式重定向似乎绕过了UrlRewriteFilter所依赖的URL编码器。
public void preRenderView(ComponentSystemEvent e) throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect("pages/index.xhtml");
}