会话到期后,Primefaces组件不响应

时间:2013-07-10 14:31:46

标签: jsf primefaces

我有一个检查会话的过滤器。我的过滤器:

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

1 个答案:

答案 0 :(得分:1)

最有可能的是,您对托管bean进行了ajax调用。这就是为什么错误导航在web xml中不起作用的原因。如果将操作作为ajax请求调用,则会将错误发送到JavaScript回调onerror

如果要处理服务器端的错误,可以向应用程序添加全局异常处理程序。 Adding global exception handling using JSF教程是一个很好的教程。

此外,您可以使用FullAjaxExceptionHandler

OmniFaces功能