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

Regarding valueBound & valueUnbound events

 
Mike lothar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i couldn't understand event notifications clearly regarding valueBound & valueUnbound events. if there is a toy object that implements HttpSessionBindingListener interface if its bound to session attribute for example. if i execute below lines
Toy toy = new Toy();

session.setAttribute("Toy1",toy);
session.setAttribute("Toy1",toy);

events are called in following manner

valueBound()
valueBound()
valueUnbound().

why valueUnbound() event is called please explain.

Thank you
Mike.
 
Ronald Jerue
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mike,

I ran the same test below and this is the output. It looks like this is what's happening. When setAttribute() is called a second time for the attribute "breed" Tomcat is simply doing some internal cleanup and removing the original object bound to the "breed" attribute and setting to null. This internal cleanup is causing an HttpSessionBindingEvent for valueUnbound() to occur.

(My code)
HttpSession session = request.getSession();
Dog dog = new Dog("Airedale");
session.setAttribute("breed", dog);
session.setAttribute("breed", dog);

(My output)
valueBound(): breed=com.example.Dog@1701bdc
valueBound(): breed=com.example.Dog@1701bdc
valueUnbound(): breed=null

[ December 27, 2004: Message edited by: Ronald Jerue ]
[ December 27, 2004: Message edited by: Ronald Jerue ]
 
Mike lothar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ronald, i got it

Mike
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic