我一直在尝试缓存和处理会话,如果抛出一个` `viewExpiredexceptionviewExpiredexception,我编写了一个自定义的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>我在上面的操作中取得了有限的成功,它在某些情况下可以工作,但在其他情况下,页面根本不会重定向。它主要在chrome中工作,但在IE中它根本不能工作。
我试着做一些更改,比如使用
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
response.sendRedirect(vee.getViewId());但是我得到了500个错误页面,异常地写着View must Exists...,所以我停止了实验,首先找出我做错了什么。如何才能实现调用ViewExpiredException并重定向回抛出错误的页面的目标?
我使用的是myFaces (2.1.7)和richFaces (3.3.3)。谢谢
发布于 2012-06-11 20:12:05
在MyFaces社区中已经做了一些工作来以一种优雅的方式处理ViewExpiredException。在MyFaces核心中已经解决了一些问题(参见MYFACES-3530和MYFACES-3531),也许你应该尝试一下最新的快照HERE。
https://stackoverflow.com/questions/10978457
复制相似问题