You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jon Wilmoth <jo...@yahoo.com> on 2006/12/13 20:22:35 UTC

Struts2 Storing/Retrieving View objects

I'm preparing to make the switch from Struts 1.x to Struts 2 for new development and had a few questions related to how objects used to render data in a JSP page should be stored/retrieved for a desired http namespace. One of the design tenants I try to employ in my current S1 webapp is minimizing HttpSession bloat by storing objects needed to render jsp pages as request attributes instead of session attributes. I understand S2 has tried to insulate the actions from the http communication details by introducing the ValueStack. I generally like the idea, but I'm having a difficult time understanding how/when different items are pushed/popped. For example in my S1 action if I knew the target jsp result page needed a list of objects as well as the current user to display info I'd bind the objects to the view like so: 

//List only need to render immediate next page 
request.setAttribute("myListOfObjects", objectList); 
//User needed to render immediate next page and other page 
session.setAttribute("currentUser", currentUser); 

How would I bind the objects in S2 such that the objectList is not present in the ValueStack after the request? How do I ensure the currentUser is present in the ValueStack for multiple requests? 

Thanks in advance, 
Jon 

p.s. I've read through both the "Comparing Struts 1 and 2" and "Struts 1 Solutions" guides and didn't find the answer to my question.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 Storing/Retrieving View objects

Posted by Don Brown <do...@gmail.com>.
Just provide getter methods on your action.  Then, you can retrieve
the data in your jsp through either jsp expressions - ${myProp} - or
the Struts 2 tags.  Struts 2 makes your action object's properties
automatically available to your jsp or other template file.

Don

On 12/13/06, Jon Wilmoth <jo...@yahoo.com> wrote:
> I'm preparing to make the switch from Struts 1.x to Struts 2 for new development and had a few questions related to how objects used to render data in a JSP page should be stored/retrieved for a desired http namespace. One of the design tenants I try to employ in my current S1 webapp is minimizing HttpSession bloat by storing objects needed to render jsp pages as request attributes instead of session attributes. I understand S2 has tried to insulate the actions from the http communication details by introducing the ValueStack. I generally like the idea, but I'm having a difficult time understanding how/when different items are pushed/popped. For example in my S1 action if I knew the target jsp result page needed a list of objects as well as the current user to display info I'd bind the objects to the view like so:
>
> //List only need to render immediate next page
> request.setAttribute("myListOfObjects", objectList);
> //User needed to render immediate next page and other page
> session.setAttribute("currentUser", currentUser);
>
> How would I bind the objects in S2 such that the objectList is not present in the ValueStack after the request? How do I ensure the currentUser is present in the ValueStack for multiple requests?
>
> Thanks in advance,
> Jon
>
> p.s. I've read through both the "Comparing Struts 1 and 2" and "Struts 1 Solutions" guides and didn't find the answer to my question.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org