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

Listener question

 
Fu Dong Jia
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

which interface must a class implement so that instances of the class are notified after any object is added to a session?
a, javax.servlet.http.HttpSessionListener
b, javax.servlet.http.HttpSessionValueListener
c, javax.servlet.http.HttpSessionBindingListener
d, javax.servlet.http.HttpSessionAttributeListener

the answer is c,but I think the answer should be d.
Am i wrong?
the key words "any object" is the class's instance?
thanks in advance.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would also say "d".
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too think answer should be d
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you quote your source ?
 
Nitin Vashishtha
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct answer would be C.
If you read the question statement carefully ,it says that "instances of the class are notified after any object is added to a session"
this is the case when the instances are notified whenever they are added or removed to or from any session.
In this case the calss,instance of which you are adding as a session attribute should implement HttpSessionBindingListener interfce and should override valueBound(HttpSessionBindingEvent event) and valueUnbound(HttpSessionBindingEvent event) methods and this is the only listener you dont need to declare in DD.
 
Amar Nath Verma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer should be d as question states that "after any object is added to a session"
 
Reesha Ashok
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

HttpSessionAttributeListener lets you track each time an attribute has been added, removed or replaced from session.This interface is implemented by some other class which is not an "attribute" class.
Say for example, Dog is an attribute class* and MyAttributeListener is a class that implements HttpSessionAttributeListener, then MyAttributeListener class will be notified everytime a Dog object is added,removed or replaced from the session.The dog object is never notified of this events.

HttpSessionBindingListener on the other hand lets the objects of the attribute class* to be notified when they are bound (added) to or unbound (removed) from a session..This interface is implemented always by an attribute class*.
To make this clear, the attribute class Dog implements HttpSessionBindingListener so that instance of the dog object is notified when any dog object is added to removed from session.

*Attribute class - A class for an object that will be used an attribute value

HttpSessionAttributeListener notifies SESSION about changes to attributes.
HttpSessionBindingListener notifies a CLASS INSTANCE about object binding (bound or unbound to session.)


which interface must a class implement so that instances of the class are notified after any object is added to a session?

Since the question is about notifying the instance of the class(Note it's not about notifying session) about object added , I think the correct answer should be c - HttpSessionBindingListener

Hope this helps..!!!
[ April 07, 2008: Message edited by: R Nellika ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"instances of the class are notified after any object is added to a session"

"Any object" is the problem here. Any object of which class ? It's not written which class, so I assume that it really is any object. So the answer could not be "c".
 
Nitin Vashishtha
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the confusion.Now I have got the point.
Originally posted by Christophe Verre:

"Any object" is the problem here.


Thats correct,if it is really "any" object,the answer will be d.
Actually,HttpSessionAttributeListener will be notified whenever "any" object is added or removed from a session,additionally, if any class named as 'A' implements HttpSessionBindingListener and the value which is being bound to the session is an instance of class A,then both the listerners will be notified in this case.so in any case,HttpSessionAttributeListener will always be notified.As far as the above question is concerned,the correct answer will be d.
 
Reesha Ashok
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Christophe Verre:

"Any object" is the problem here. Any object of which class ? It's not written which class, so I assume that it really is any object. So the answer could not be "c".

You are right in that case.I didn't take notice of the term "any" in the question.
 
Rhett Wang
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
Now I fully understand the difference between javax.servlet.http.HttpSessionBindingListener
and javax.servlet.http.HttpSessionAttributeListener
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic