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

Doubts in the valuebound, valueUnbound invocation

 
akshay ranganath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a simple class that implements the HttpSessionBindingListener, called Toy. It just has a variable, to store the Toy name.

I created a servlet called, SessionServlet that created two objects of the above class. This is the code piece:

HttpSession session = request.getSession();
Toy toy1 = new Toy("doll");
Session.setAttribute("toy", toy1);
Toy toy2 = new Toy("ball");
Session.setAttribute("toy", toy2);

As the Toy is implementing the binding listener interface, it should display the following lines:

valueBound (for the attribute "toy", with value, let's say Toy@111)
valueUnbound: (for attribute "toy", with value, as null)
valueBound (for attribute "toy" with new value say Toy@222).

But, in the actual output, I'm getting, valueBound (for attribute "toy" value Toy@111)

This is the actual output from the Tomcat server:
-------------------------------------------------

Toy: valueBound name:toy value: Toy@602b6b
AttributeListener: Attribute added!
Name: toy value Toy@602b6b

Toy: valueUnbound name:toy value: null

Toy: valueBound name, toy value: Toy@602b6b
AttributeListener: Attribute Replaced!
Name: toy value Toy@602b6b
------------------------------------------------

Could anyone please explain how these values are obtained?

Thanks,
Akshay
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implement a toString in your Toy class and see what happens?
 
akshay ranganath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried by overloading the toString method. It is supposed to return the Toy name variable's value.

Now, instead of the object memory signature, it is printing null, instead of the toy's name.

Regards,
Akshay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic