Alex Rivera | Logout

How to invalidate session in JSF 2.0?

Asked 2011-04-11T10:14:39.227
64

What is the best possible way to invalidate session within a JSF 2.0 application? I know JSF itself does not handle session. So far I could find

private void reset() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
            .getExternalContext().getSession(false);
    session.invalidate();
}
  1. Is this method correct? Is there a way without touching the ServletAPI?
  2. Consider a scenario wherein a @SessionScoped UserBean handles the login-logout of a user. I have this method in the same bean. Now when I call the reset() method after I'm done with necessary DB updates, what will happen to my current session scoped bean? since even the bean itself is stored in HttpSession?
Edit
Report

1 Answer

13
public void logout() {
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
}
answered 2012-07-19T09:57:04.027

Your Answer