Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Event Notification

 
Ed Ward
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings!

Suppose you have an HttpSessionAttributeListener and an
Object which implements HttpSessionBindingListener.
Since both receive an HttpSessionBindingEvent, which
one would be notified first when the Object which implements
HttpSessionBindingListener is added to (or replaced in) a session?

I haven't tested this out yet, however, it seems to me that
the Object implementing HttpSessionBindingListener should be notified
first as by the time the HttpSession.setAttribute(String, Object) call
completes, and the session realizes that an attribute was added,
the Object which was added should already be aware of the fact.

If this is the case, does the same hold true when it is explicitly
removed from a session or the session is invalidated?

Right or wrong, is the behavior guaranteed (not vendor specific)?
I though I read about this recently but am unable to locate the reference.

Thanks.
 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Yes you are right , when we bind an object to a
session using the setAttribute(String name,Object value)
method and if the object implements HttpSessionBindingListener,
the container first calls HttpSessionBindingListener.valueBound
and then it notifies any HttpSessionAttributeListeners in the web application.

Same is true in case of removeAttribute()

For reference check Session Attributes section of http://java.boot.by/wcd-guide/ch03s02.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic