首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过重定向的方式处理viewExpiredexception

通过重定向的方式处理viewExpiredexception
EN

Stack Overflow用户
提问于 2012-06-11 18:32:40
回答 1查看 650关注 0票数 1

我一直在尝试缓存和处理会话,如果抛出一个` `viewExpiredexceptionviewExpiredexception,我编写了一个自定义的viewExpiredexception处理程序,它应该重定向回抛出异常的页面,我还将一个布尔值插入到会话中,它在被拒绝的页面中使用,以显示“页面已刷新”消息。

下面是我的ViewExpiredException处理程序的相关部分:

代码语言:javascript
复制
     public void handle() throws FacesException {
            for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
                ExceptionQueuedEvent event = i.next();
                ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
                Throwable t = context.getException();
                if (t instanceof ViewExpiredException) {
                    ViewExpiredException vee = (ViewExpiredException) t;
                    FacesContext fc = FacesContext.getCurrentInstance();
                    Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();
                    NavigationHandler nav =  fc.getApplication().getNavigationHandler();
                    try {
                        requestMap.put("currentViewId", vee.getViewId());
                        HttpServletRequest orgRequest = (HttpServletRequest) fc.getExternalContext().getRequest();
                        fc.getExternalContext().redirect(orgRequest.getRequestURI());
                        Map<String, Object> sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
                        sessionMap.put("refreshedMaxSesion",true);
                        fc.renderResponse();
                    }
                    catch(IOException e){   }
                    finally {   i.remove(); }
                }
            }
            // here queue will not contain any ViewExpiredEvents, let the parent handle them.
            getWrapped().handle();
      }

和导航案例

代码语言:javascript
复制
           <navigation-rule>
              <navigation-case>
               <from-outcome>/app/ord1</from-outcome>
               <to-view-id>/jsp/orderHist.jsp</to-view-id>
               <redirect />
              </navigation-case>
            </navigation-rule>

我在上面的操作中取得了有限的成功,它在某些情况下可以工作,但在其他情况下,页面根本不会重定向。它主要在chrome中工作,但在IE中它根本不能工作。

我试着做一些更改,比如使用

代码语言:javascript
复制
 HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
       response.sendRedirect(vee.getViewId());

但是我得到了500个错误页面,异常地写着View must Exists...,所以我停止了实验,首先找出我做错了什么。如何才能实现调用ViewExpiredException并重定向回抛出错误的页面的目标?

我使用的是myFaces (2.1.7)和richFaces (3.3.3)。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-11 20:12:05

在MyFaces社区中已经做了一些工作来以一种优雅的方式处理ViewExpiredException。在MyFaces核心中已经解决了一些问题(参见MYFACES-3530MYFACES-3531),也许你应该尝试一下最新的快照HERE

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10978457

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档