Search code examples
sessioncachingxpagesjavabeans

userBean is not updated when I login as a new user


I have a session Scoped user bean which loads user data into memory when the application is launched. The user bean data is used throughout the application for getting data i.e email etc.

I have noticed that if I logout, the old user data is still displayed from the bean and it does not help to close the browser.

How can I resolve this issue?


Solution

  • I run the following code to clear the sessionScope on logout:

    val = context.getSubmittedValue();
    if (val == "logout") {
        facesContext.getExternalContext().getSession(false).invalidate();
        href=facesContext.getExternalContext().getRequest().getContextPath() + "?Logout&redirectTo=" + facesContext.getExternalContext().getRequest().getContextPath() ;
        facesContext.getExternalContext().redirect(href);
    }