【问题标题】:Handling ViewExpiredException depending on the current view根据当前视图处理 ViewExpiredException
【发布时间】:2011-11-26 06:03:16
【问题描述】:

我在我的项目中使用 JSF 2.0 和 Primefaces。

我有两个 xhtml 页面,即 Cars.xhtml 和 Bikes.xhtml。

我正在使用 ViewScoped 支持 bean。

目前如果从两个页面中的任何一个获取视图过期异常,我会在 web.xml 中处理它。 通过错误页面标签并指向welcome.xhtml。

现在,如果我从 Bikes.xhtml 中获得 viewexpired 异常 我需要指向另一个页面,即 BikesHome.xhtml 而不是welcome.xhtml。

如果异常来自 Cars.xhtml,则应显示welcome.xhtml。

请帮我看看怎么办。

【问题讨论】:

    标签: jsf jsf-2 primefaces viewexpiredexception


    【解决方案1】:

    我对此不是 100% 确定(因为我自己没有尝试过),但这是我的建议 - 看看这个Dealing Gracefully with ViewExpiredException in JSF2

    if (t instanceof ViewExpiredException) {
        ViewExpiredException vee = (ViewExpiredException) t;
    

    此时可以得到view id如下-

    vee.getViewId();
    

    然后根据view id做想要的导航。

    NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
    //check condition, set view       
    nv.handleNavigation(facesContext, null, "/view-id?faces-redirect=true");
    facesContext.renderResponse();
    

    或者,我认为你也可以这样做 -

    FacesContext.getExternalContext().redirect(url);
    FacesContext.responseComplete();
    

    重定向。

    【讨论】:

    • 关于您分享的链接中的过滤器的快速问题,当达到超时时,handle() 方法将被自动调用,这会强制页面重定向还是用户需要点击某些东西?
    猜你喜欢
    • 1970-01-01
    • 2012-02-12
    • 2017-07-27
    • 2014-02-14
    • 1970-01-01
    • 2013-03-19
    • 2017-10-26
    • 2014-01-17
    • 1970-01-01
    相关资源
    最近更新 更多