• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what listeners don't need to register in DD

 
Will Lee
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HFSJ said: ServletContextListener must be registered in DD, and HttpSessionBindingListener don't have to since it "happens automatically".

The API has this line "To receive notification events, the implementation class must be configured in the deployment descriptor for the web application." for all ctx and req listeners, as well as HttpSessionListener. For other 3 Session Listeners (HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionActivationListener), API doesn't mention this line.

Does it mean these 3 listeners don't need to register in DD? :roll:
[ September 24, 2005: Message edited by: Will Lee ]
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good question...help me to re-read the HFSJ, and remind of myself to that question.

according to HFSJ, page 254--HttpSessionListener, HttpSessionActivationListener, HttpSessionAttributeListener MUST be registered in DD.

and HttpSessionBindingListener, do not be configured in DD since the Container calls the event handling (valueBound() & valueUnbound()) when an intance of certain class is added to or removed from a session.

almost the same words from HFSJ.. well it is the SAME.
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only HttpSessionListener and HttpSessionAttributeListener are configured in the DD.

HttpSessionActivationListener and HttpSessionBindingListener are not configured in DD. They are implemented by the attibute class.
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh...sorry i was wrong.

Edmund is correct.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Edmund,

I agree with you that HttpSessionBindingListener and HttpSessionActivationListener do not need to be declared in DD. However, my conclusion is based on my own logical guess. I just want to know which part of the spec does have a clear definition of this requirement?
 
Will Lee
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check J2ee API (or servlet API, or maybe the spec.), There's description for HttpSessionListener: To be notified, the class of this type must be registered in DD.

and HFSJ only emphasized Binding and ActivationListener don't need to be, so I guess HttpSessionAttrListener may need this step.
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
according to HFSJ(Pg:254), HttpSessionActivationListener also need to be registered in DD. On what basis you guys are saying that it is not needed to register?
But HFSJ book doesnt talk much on other types of listerners also. My question is request and context listeners need to be registerd in DD or not?
I am guessing except HttpSessionBindingListner, all other listeners must be registered in DD.
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
according to HFSJ(Pg:254), HttpSessionActivationListener also need to be registered in DD. On what basis you guys are saying that it is not needed to register?


Please check the errata.
 
Gouri Bargi
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

A trick to remember which event listeners to register in the DD :

The listeners can be classified in 2 categories:

1. Those that are interested in all events of one type(e.g. HttpSessionListener (interested in ALL Http session creation and destruction events), HttpSessionAttributeListener(interested in all session attribute events - any attribute added / removed / replaced), and all the listeners for ServletContext and ServletRequest.

The container creates one instance of each of these listeners.

2. Those that are interested only in specific events of one type. (there are 2 listeners of this type - HttpSessionBindingListener (interested in knowing when it is itself bound / unbound to a HttpSession) and HttpSessionActivationListener(interested in knowing when only the session it is bound to is activated or passivated, so that it can prepare itself for activation / passivation)

We create the instances of these listeners and set them as attributes in specific http sessions.


The first type of listeners are configured in the DD - as their methods are ALWAYS called when the event occurs.

The second type of listeners are not configured in the DD.

On page 262 in HFSJ, it is mentioned that HttpSessionActivationListener interface may usually be implemented by an attribute class or some other class. I think this is not correct - HttpSessionActivation should always be implemented by an attribute class.
- Gouri
[ September 27, 2005: Message edited by: Gouri Bargi ]
 
Will Lee
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I agree. I think the HSActivationListener should not be implemented by "other" class.

Thanks for giving such detail explaination. I guess an easy way to remember is: All listener that are implemented by attribute obj. should NOT be registered in DD. They are HSBindingListener and HSActivationListener. For everything else (servlet context and request, other HttpSession listener), you must declare in DD. The order of them in DD matters.
 
Ner min
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
where i can find the errata for the scwcd i looked here and on wickedlysmart.com but havent find anything?
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where i can find the errata for the scwcd i looked here and on wickedlysmart.com but havent find anything?

Just search for "errata" in this forum.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic