• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Practical use of listeners

 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody please mention the use of listeners in practical applications you have used besides being used for logging or testing purposes?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the most common ones is probably the use of ServletContextListener for performing context-wide initializations (what in years past might have been done by a load-at-startup servlet).

SessionListener is very handy for seperating the creation of user sessions from per-user initilization.

Generally, listeners let you separate certain events from actions that should be triggered when those events occur.
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd add "debugging" to that list.

We recently had a web app, where things were being added to the session in many places but not all of them were serializable, leading to a failure.

Not being the original author of this web app, I wrote a SessionAttributeListener which flagged up an error if the added object wasn't serializable.

This certainly sped up the tracing of these illusive objects.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf for giving practical use of Listeners.

Nice example Mark!


Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic