You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jun Bihag <ju...@dmrguam.com> on 2005/12/09 02:33:40 UTC

How to refer to a previous ActionForm that is in a session scope?

I am developing a web application that goes from one page to another 
using two different Action classes. The initial page is connected to a 
session scoped ActionForm. On the second page which is handled by 
another Action (and its corresponding ActionForm that is request 
scoped), I want to access the variables on the first session scoped 
ActionForm. Is there a way to directly refer to the first ActionForm? 
Right now, I save the first ActionForm as a session attribute so that I 
can refer to it in the second Action. I hope that I am stating this clearly.

Thanks,
Jun


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


Re: How to refer to a previous ActionForm that is in a session scope?

Posted by Jun Bihag <ju...@dmrguam.com>.
Thanks, Michael. A simple attribute name change frees up the redundant 
memory used in my previous approach.

Michael Jouravlev wrote:
> On 12/8/05, Jun Bihag <ju...@dmrguam.com> wrote:
>   
>> I am developing a web application that goes from one page to another
>> using two different Action classes. The initial page is connected to a
>> session scoped ActionForm. On the second page which is handled by
>> another Action (and its corresponding ActionForm that is request
>> scoped), I want to access the variables on the first session scoped
>> ActionForm. Is there a way to directly refer to the first ActionForm?
>> Right now, I save the first ActionForm as a session attribute so that I
>> can refer to it in the second Action. I hope that I am stating this clearly.
>>     
>
> ActionForm is just a regular Java class that is stored in request or
> session or app context object depending on the scope that you set in
> the struts-config.xml file. The name that you use to define a form
> bean in the struts-config.xml file is the key under which the form
> bean is stored in respective scope. Struts uses the same objects that
> are defined in servlet spec.
>
> The bottom line: the reference is already saved for you, you do not
> need to create another reference to an action form.
>
> Michael.
>
> ---------------------------------------------------------------------
> 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


Re: How to refer to a previous ActionForm that is in a session scope?

Posted by Michael Jouravlev <jm...@gmail.com>.
On 12/8/05, Jun Bihag <ju...@dmrguam.com> wrote:
> I am developing a web application that goes from one page to another
> using two different Action classes. The initial page is connected to a
> session scoped ActionForm. On the second page which is handled by
> another Action (and its corresponding ActionForm that is request
> scoped), I want to access the variables on the first session scoped
> ActionForm. Is there a way to directly refer to the first ActionForm?
> Right now, I save the first ActionForm as a session attribute so that I
> can refer to it in the second Action. I hope that I am stating this clearly.

ActionForm is just a regular Java class that is stored in request or
session or app context object depending on the scope that you set in
the struts-config.xml file. The name that you use to define a form
bean in the struts-config.xml file is the key under which the form
bean is stored in respective scope. Struts uses the same objects that
are defined in servlet spec.

The bottom line: the reference is already saved for you, you do not
need to create another reference to an action form.

Michael.

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


Re: How to refer to a previous ActionForm that is in a session scope?

Posted by Wendy Smoak <ws...@gmail.com>.
On 12/8/05, Jun Bihag <ju...@dmrguam.com> wrote:
> I am developing a web application that goes from one page to another
> using two different Action classes. The initial page is connected to a
> session scoped ActionForm. On the second page which is handled by
> another Action (and its corresponding ActionForm that is request
> scoped), I want to access the variables on the first session scoped
> ActionForm. Is there a way to directly refer to the first ActionForm?
> Right now, I save the first ActionForm as a session attribute so that I
> can refer to it in the second Action. I hope that I am stating this clearly.

Does it make sense in your app to consolidate the ActionForms and use
the same one for both Actions?  That way you can use the 'form' that's
passed into either Action's execute method, and all the fields will be
there.

If not, you can just retrieve the first form from session scope.  As
Michael mentioned, you don't need to store it there, the framework
will have done that for you.

(If you're not sure what's in scope, include a scriptlet or
<c:forEach> to write out the contents of the request and session at
the bottom of your JSPs during development.)

--
Wendy

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