Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 JSF2.0重定向错误_Jsf 2 - Fatal编程技术网

Jsf 2 JSF2.0重定向错误

Jsf 2 JSF2.0重定向错误,jsf-2,Jsf 2,从preRenderView事件重定向时,我收到一个非法状态异常。我只是通过引入例外情况来解决这个问题。有没有更干净的方法来达到同样的效果 @Named @RequestScoped public class LogoutBean implements Serializable { public void preRenderView(ComponentSystemEvent e) { userSessionBean.logout(); FacesC

从preRenderView事件重定向时,我收到一个非法状态异常。我只是通过引入例外情况来解决这个问题。有没有更干净的方法来达到同样的效果

@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");
}