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

Registration of Session Listeners

 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as Session Listeners are concerned, I'm a little confused about whether or not it is mandatory for the HttpSessionAttributeListener to be registered in the DD. This is my understanding:-

Following listener does not have to be registered, but can be:
HttpSessionBindingListener

Following listeners do have to be registered:
HttpSessionListener
HttpSessionActivationListener
HttpSessionAttributeListener

Could someone please confirm if this is correct?

 
Icaro Dourado
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose every listener should be declared in your DD, otherwise how could they be found?
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this: http://www.coderanch.com/how-to/java/DeclaringListeners

Those who are interested in specific types of events (like the two from the group number 2 in the link above) doesn't have to be declared.
The point is that listeners from group 1 has to be called by the container every time something changes. You don't know what particular object can change - you are listening on all events.

The second group is quite different. The container will try to execute particular method on the object and it will execute (if it's provided) or not (if it's not provided). Container doesn't need any extra information about these kind of listeners - it just tries to execute this method.

Talking about HttpSessionBindingListener - the container just executes valueBound(-) on object after you add it to the session.

HTH!
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer Pedro. I'm glad I asked the question here, because I was mistakenly going with what was in the HFSJ book.

So then I should amend what I wrote before to this:

Following listeners do not have to be registered, but can be:
HttpSessionBindingListener
HttpSessionActivationListener

Following listeners do have to be registered:
HttpSessionListener
HttpSessionAttributeListener
All ServletContext & ServletRequest event Listeners
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct Nidhi :-)

Cheers!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic