Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Struts 2: why object is removed from the ValueStack? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2: why object is removed from the ValueStack?" Watch "Struts 2: why object is removed from the ValueStack?" New topic
Author

Struts 2: why object is removed from the ValueStack?

Ramesh Babu Essampalli
Greenhorn

Joined: Oct 19, 2009
Posts: 5
I am calling an action class that initialize PersonDTO object in its execute method. This PersonDTO object have getter-setter methods in the action class. I am able to retrieve the value of PersonDTO in success.jsp page using ValueStack. but, on click of submit button in the success.jsp page, i am getting null value for PersonDTO object in the action class. value of PersonDTO object is stored into ValueStack then why its getting null? and how to resolve it.

to clarify my query, here is the action class:




success.jsp:



to get the value of PersonDTO in the action class on click of update button; i added a person bean in success.jsp, but it does not work:



i also tried putting a hidden tag, but it does not work either:



please help me in keeping person object into the valuestack.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because a form submission is a new request, hence a new value stack.
Ramesh Babu Essampalli
Greenhorn

Joined: Oct 19, 2009
Posts: 5
Thank you david. then copying the person object into session object is the best way. or it there any better approach provided by struts2?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's certainly an option, although depending on your expected workload it might not be the absolute best approach. Other approaches could be to re-look up the object; if caching has been implemented it probably wouldn't require another trip to the database.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts 2: why object is removed from the ValueStack?