【问题标题】:Primefaces component not respond after the session expiredPrimefaces 组件在会话过期后没有响应
【发布时间】: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


【解决方案1】:

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

如果您想在服务器端处理错误,您可以向应用程序添加全局异常处理程序。 Adding global exception handling using JSF 教程很不错。

此外,您还可以使用OmniFacesFullAjaxExceptionHandler 功能

【讨论】:

  • 我不是说你错了。我只是想了解您的答案,以防将来遇到类似问题。所以,如果我听起来像我,请原谅我。当ajax 出现问题时调用onerror 函数,请求没有?这与导航有何关系?你能解释一下吗?
  • 我使用第一种方式全局异常handlinb,但我有一点问题。我编辑了我的第一篇文章。
  • 您的问题现在似乎与第一个问题完全不同,这使我的回答毫无价值。对于面临同样问题的其他用户,我的回答完全没有意义。当您的问题发生变化时,请提出另一个问题。 @Orange91,我很高兴你解决了。
猜你喜欢
  • 2011-11-07
  • 2016-01-07
  • 2014-08-14
  • 2023-02-07
  • 2012-04-17
  • 1970-01-01
  • 1970-01-01
  • 2016-06-21
相关资源
最近更新 更多