【发布时间】:2013-07-08 13:05:27
【问题描述】:
我有一个过滤器来检查会话。我的过滤器:
public class FilterLogin implements Filter{
FilterConfig fc;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
fc = filterConfig;
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
HttpSession session = req.getSession(true);
if (session.getAttribute("loginMB") == null) {
resp.sendRedirect("/home.xhtml");
} else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
web.xml:
<filter>
<filter-name>filter</filter-name>
<filter-class>pl.ePrzychodnia.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>filter</filter-name>
<url-pattern>/protected/*</url-pattern>
</filter-mapping>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/home.xhtml</location>
</error-page>
当会话到期时,我应该访问站点 home.xhtml。但是当会话过期并且我想点击页面中的导航菜单时,组件没有对点击做出反应...... 当我不使用 Primefaces 时,一切正常。当我在我的项目中使用 primefaces 时,我遇到了这个错误。可能是什么原因?
我尝试使用全局异常处理程序,但我有一个小问题。我从这个网站复制课程http://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/
并在 CustomExceptionHandler 类中编辑:
try {
//log error ?
log.log(Level.SEVERE, "Critical Exception!", t);
//redirect error page
requestMap.put("exceptionMessage", t.getMessage());
nav.handleNavigation(fc, null, "/home");
fc.renderResponse();
// remove the comment below if you want to report the error in a jsf error message
//JsfUtil.addErrorMessage(t.getMessage());
}
我将:nav.handleNavigation(fc, null, "/error"); 更改为 nav.handleNavigation(fc, null, "/home");
但是当会话超时时,我不会重新编辑到 home.xhtml 页面,只有在我单击时才会转到该页面,并且我有一个示例错误:
SEVERE: Critical Exception!
javax.faces.application.ViewExpiredException: viewId:/protected/admin/about.xhtml - View /protected/admin/about.xhtml could not be restored.
当我的会话过期时单击“关于”页面的引用。我看到一个不完整的 about.xhtml 页面而不是 home.xhtml
【问题讨论】:
-
您是否收到任何错误消息?哪个 primeface 和 JSF 版本?
-
你可以试试 primefaces idleMonitor
-
将 xhtml 部分发布在您遇到问题的地方。
标签: jsf primefaces