2012-06-11 44 views
1

我一直在试图缓存和处理viewExpiredexception如果viewExpiredexceptionviewExpiredexception是抛出,我已经写了一个自定义的viewExpiredexception处理程序,它假定重定向回抛出异常的页面,我还要在会话中插入一个布尔值,用于更新页面以显示“页面已刷新”消息。通过重定向处理viewExpiredexception

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

 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(); 
     } 

和导航的情况下

  <navigation-rule> 
       <navigation-case> 
       <from-outcome>/app/ord1</from-outcome> 
       <to-view-id>/jsp/orderHist.jsp</to-view-id> 
       <redirect /> 
       </navigation-case> 
      </navigation-rule> 

我了有限的成功与上面,它会在某些情况下,但在其他情况下工作该页面根本不会重定向。它主要用于浏览器,但在IE中它根本不起作用。

我试图使一些变化,如使用

HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse(); 
     response.sendRedirect(vee.getViewId()); 

,但我得到的500个错误页面,出现异常说View must Exists...,所以我停止试验,以找出什么,我第一次做错了。这个如何实现将ViewExpiredException和Redirectign重定向到引发错误的页面的目标被归档?

我在myFaces(2.1.7)和richFaces(3.3.3)上。谢谢

回答

1

在MyFaces社区内已经做了一些工作,以优雅的方式处理ViewExpiredException。 MyFaces Core解决了一些问题(请参阅MYFACES-3530MYFACES-3531)也许您应该尝试最新的快照HERE