On 4/10/07 3:00 AM, "Alexis Pigeon" <[EMAIL PROTECTED]> wrote:

> Hi all,
> 
> My application uses a bean to store a collection of values to display
> in a select input. Since the generation of this collection is
> time-consuming, I set this bean to a session scope, and using the
> following code :
> 
> in jsp:
> <%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld" %>
> <s:set name="myCollection" value="myCollection" scope="session"/>

I wouldn't recommend doing this in the JSP. (see below)
 
> in the Action (implementing Preparable and ServletRequestAware):
> private Vector myCollection;
> public Vector getMyCollection() {
>   return myCollection;
> }
> public void setMyCollection (Vector v) {
>   this.myCollection = v;
> }
> public void prepare() {
>   ...
>   setMyCollection( (Vector)
> request.getSession().getAttribute("myCollection"));
>   ....
> }

There's a cleaner Struts 2 way of doing this. Take a look at the
org.apache.struts2.interceptor.SessionAware interface. This will make your
action independent of the servlet spec and more easily testable.

Also you ought to put the collection into the session in your action.
Setting it into the session scope in the JSP is in general a bad practice.
The view really should not change the "model" of the running app.
 
> This works perfectly as expected, as long as there is only one
> instance of the application launched at a time in the same browser
> (using Firefox or IE7 tabs for example). In that case, the bean is
> shared between the different instances, which is problematic since its
> content depends on previous data input.

You need a conversation scope. There is no direct support for this in the
Servlet spec, nor in Struts 2 directly. You could take a look at using the
Spring Webflow integration (I don't know the link). You could also take a
look at a simple interceptor I created for this purpose.
(http://www.vitarara.org/cms/node/84) I have since updated that method to
simply be an extension of ModelDriven, if you're interested in the most
recent version let me know.
 
Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to