I want to know about setting and un-setting the session in JSF2.0. Although following some blogs and books (Core JavaServer Faces-3rd Edition), i got to know that using annotation @SessionScoped we can set any manage bean to be in session. I have a loginBean which is @ManagedBean and SessionScoped declared. On the top right corner, my web has login button.
When this session is created (i am not setting it manually, that is why i am confused) and when i gets destroyed? It must be destroyed either by time out or by clicking in logout button only.
I want to know about setting and un-setting the session in JSF2.0. Although following
Share
JSF uses the Servlet API under the covers. A session scoped managed bean is in essence set as an attribute of the
HttpSession. It will be created and set whenever the EL expression referencing the managed bean#{sessionBean}is evaluated for the first time. It will be “removed” from the session whenever the session expires (by either a restart of the client or a timeout in the server) or get invalidated. If you let your logout button callExternalContext#invalidateSession(), then the session will be invalidated.If you’re familiar with the basic Servlet API, you should already understand how this all works. For an in-depth explanation of the Servlet’s
HttpSessionworks under JSF’s covers, read this answer: How do servlets work? Instantiation, sessions, shared variables and multithreading.