The Nightmare
The Nightmare

Reputation: 701

Primefaces component not respond after the session expired

I have a filter which checks the session. My filter:

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>

When the session is expired I should go to the site home.xhtml. But when the session is expired and I want click the navigation menu in the page, the component is not reacting to the click... When I do not use Primefaces everything works correctly. When I use primefaces in my project I have this error. What could be the cause?

I try use a global exception handler but i have a little problem. I copy class from this site http://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/

and edited in class 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());

            } 

I change: nav.handleNavigation(fc, null, "/error"); to nav.handleNavigation(fc, null, "/home");

But when session timeout i not reditect to home.xhtml page only go to the page when I clicked and i have a example error:

SEVERE: Critical Exception!
javax.faces.application.ViewExpiredException: viewId:/protected/admin/about.xhtml - View /protected/admin/about.xhtml could not be restored.

when i clicked reference to about page when my session expired. I see a incomplete about.xhtml page instead home.xhtml

Upvotes: 0

Views: 3612

Answers (1)

erencan
erencan

Reputation: 3763

Most possibly, you make an ajax call to the managed bean. That is why error navigation does not work in web xml. The error will be send to JavaScript callback onerror if the action is invoked as ajax request.

You can add a global exception handler to application if you want to handle errors on server side. Adding global exception handling using JSF tutorial is a good one to follow.

Furthermore, you can use FullAjaxExceptionHandler feature of OmniFaces

Upvotes: 1

Related Questions