views:

27

answers:

1

I would like to understand the full meaning of the @SessionScoped annotation in a JSF ManagedBean.

I guess it is related to the http session, but still, it's not very clear to me when it starts, when it ends and if it can be interrupted.

  • If I leave a browser open, without activity, during 2 hours. Is the session still open?
  • Is a session shared across browser tabs
  • Does a session behave identical in say Firefox, IE or Safari?
  • ...
+2  A: 
  1. no, the session times-out if there is no activity
  2. yes, the session is shared across browser tabs
  3. yes, the session is a server-side notion mainly, browsers only send a cookie to identify

The session starts when the user requests the first page.

The @PostConstruct method of session scoped beans (if exists) is invoked when you first access a page that references that bean (I'm not entirely sure in this, though)

The session ends when you call session.invalidate() or when it times-out (the timeout period if configurable in web.xml). Then the @PreDestroy method (if exists) is invoked.

Bozho