aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes what listeners don't need to register in DD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "what listeners don Watch "what listeners don New topic
Author

what listeners don't need to register in DD

Will Lee
Ranch Hand

Joined: Mar 16, 2005
Posts: 58
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 ]

SCJP 1.4, SCWCD, SCDJWS
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
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.


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
Only HttpSessionListener and HttpSessionAttributeListener are configured in the DD.

HttpSessionActivationListener and HttpSessionBindingListener are not configured in DD. They are implemented by the attibute class.


SCJP 1.2, SCWCD 1.4
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
oh...sorry i was wrong.

Edmund is correct.
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
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

Joined: Mar 16, 2005
Posts: 58
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

Joined: Sep 02, 2005
Posts: 445
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.


Rizwan
SCJA, SCJP, SCWCD, SCBCD, SCDJWS.
Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
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

Joined: Sep 29, 2002
Posts: 47
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

Joined: Mar 16, 2005
Posts: 58
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

Joined: Sep 14, 2005
Posts: 76
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

Joined: Nov 16, 2003
Posts: 164
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what listeners don't need to register in DD