Problem session, Prime Faces view could not be restored

1

I have a JSF application but after a while I close the session but it gives me the following error and does not redirect to the login.

public String cerrarSession() {
    SessionUtils.getSession().invalidate();
    return "/login";
}

SessionUtils class

public class SessionUtils {

public static HttpSession getSession() {
    return (HttpSession) FacesContext.getCurrentInstance()
            .getExternalContext().getSession(false);
}

public static HttpServletRequest getRequest() {
    return (HttpServletRequest) FacesContext.getCurrentInstance()
            .getExternalContext().getRequest();
}

public static String getUserName() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
            .getExternalContext().getSession(false);
    return session.getAttribute("username").toString();
}

public static String getUserId() {
    HttpSession session = getSession();
    if (session != null) {
        return (String) session.getAttribute("userid");
    } else {
        return null;
    }
}

}

  

Severe: javax.faces.application.ViewExpiredException: viewId: ...

     

The view could not be restored ....

    
asked by Heinz Keydel 19.08.2016 в 21:24
source

2 answers

1

It seems that your view when invalidating the session is no longer available. Try redirect.

 public static final String LOGOUT_PAGE_REDIRECT = "/login.xhtml?faces-redirect=true";

In logout method:

 public String cerrarSession() {

        // Se invalida la sesion
        LOGGER.debug("invalidando sesion....");
        FacesContext.getCurrentInstance().getExternalContext()
                .invalidateSession();

        LOGGER.info("Sesion invalidada! ");
        return LOGOUT_PAGE_REDIRECT;
    }
    
answered by 27.04.2017 в 16:54
0

Your problem should be on the browser side, you can try implementing the following primefaces component

<p:poll interval="#{session.maxInactiveInterval}" listener="#{tuBean.cerrarSesion()}" />

The session.maxInactiveInterval is the maximum time of your session measured in seconds

    
answered by 22.02.2017 в 17:57