0


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.

Ravi Joshi
  • 5,790
  • 18
  • 66
  • 133

2 Answers2

1

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 call ExternalContext#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 HttpSession works under JSF's covers, read this answer: How do servlets work? Instantiation, sessions, shared variables and multithreading.

Community
  • 1
  • 1
BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
  • okkkk.... that's interesting... is invalidating a session and un-setting a session refer to the same thing? – Ravi Joshi Feb 23 '12 at 09:38
  • I think so. At least the phrase "un-setting a session" does technically not make any sense. Most likely you just meant the same but you used wrong terminology. – BalusC Feb 23 '12 at 13:08
0

In jsf 2.0 we can set total class ob as session like i mention

Class_name sm;

ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext(); extContext.getSessionMap().put("Give name for access this property",sm);

Class_name sm = (Class_name) extContext.getSessionMap().get("Give name for access this property");

Ghanshyam
  • 83
  • 1
  • 2
  • 8