我一直在尝试缓存和处理viewExpiredexception
如果抛出 `viewExpiredexceptionviewExpiredexception 的位置,我编写了一个自定义 viewExpiredexception 处理程序,它假设重定向回抛出异常的页面,我还在会话中插入一个布尔值,用于redicted 页面显示“页面已刷新”消息。
下面是我的 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) 上。谢谢