You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Hill <an...@gridnode.com> on 2002/12/18 03:49:18 UTC

Multiple forms in session [WAS: RE: how to send actionForm from one action to another action]

One thing Ive never understood about forms in session scope, is how does
struts deal with the situation where there are two concurrent requests in
the same session both of which are for the same action (and form type)?

As far as I can make out however, the key for a form is fixed without a way
to differentiate different instances of the same form type. Is this actually
the case or havent I read the code closely enough?

<example>
You have a page: editWotsits.jsp that uses the WotsitActionForm and submits
to WotsitAction. The requirement is that the wotsit pages open in new
windows (ie: <a target="_new"...) or frames, such that the user can be in
the process of editing multiple wotsits at any given time. Due to some other
requirements (fancy workflow perhaps?) the request scope isnt an option and
these WotsitActionForms all need to be in session scope.
</example>




-----Original Message-----
From: Eddie Bush [mailto:ekbush@swbell.net]
Sent: Wednesday, December 18, 2002 11:34
To: Struts Users Mailing List
Subject: Re: how to send actionForm from one action to another action


It's actually a combination of the module name and the form name.  Now
that we have modules, a strategy has to be used which allows each module
to have forms of the same name.  The source code would definitely be the
place to see exactly how the name is arrived at - I'd tell you, but I
haven't looked at it since it was updated.

Taylor Cowan wrote:

>>Hi, how to send actionForm from one action to another action.
>>
>>
>If the form is specified as "session" scope in struts-config, it will
always
>be available to you from req.getSession().getAttribute(key).
>
>I don't know exactly what key struts uses, but it could be found out by
>reading the source code or inspecting all keys in your session scope.  My
>guess is that it's the form's name, which should be unique.
>
>Taylor cowan
>

--
Eddie Bush





--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Multiple forms in session [WAS: RE: how to send actionForm fromone action to another action]

Posted by Affan Qureshi <qu...@etilize.com>.
Is there a way to instantiate multiple instances of actionForm beans under
different names? Also the <html:form> and action should lookup beans using a
dynamic string rather than one from struts-config.xml. We can create unique
names by appending some Id to the names. This way we might be able to avoid
name conflicts and still be able to work with multiple forms simultaneously.
Is this possible in any way? Or what is a better solution for this?

I dont want to make the bean request-scope because session-scope beans allow
for better functionality. BTW I am using Nested tags in this case.

Thanks and regards,

Affan

----- Original Message -----
From: "Eddie Bush" <ek...@swbell.net>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, December 18, 2002 11:32 AM
Subject: Re: Multiple forms in session [WAS: RE: how to send actionForm
fromone action to another action]


> Eddie Bush wrote:
>
> > They'd get trampled :-(  In fact, there's really not a good solution
> > that comes to mind.  The only single thing I see that we can do to
> > make using session-based forms more safe is to add the module name to
> > the key we use to place the forms into scope.  I'm going to go look
> > for that bug now - nearly certain it's there.
>
> ... and I have yet again managed to show my imperfection - I was wrong!
>  I sure thought such a bug existed, but I guess it must have been a
> discussion instead of a bug report.
>
> --
> Eddie Bush
>
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Multiple forms in session [WAS: RE: how to send actionForm from one action to another action]

Posted by Eddie Bush <ek...@swbell.net>.
Eddie Bush wrote:

> They'd get trampled :-(  In fact, there's really not a good solution 
> that comes to mind.  The only single thing I see that we can do to 
> make using session-based forms more safe is to add the module name to 
> the key we use to place the forms into scope.  I'm going to go look 
> for that bug now - nearly certain it's there. 

... and I have yet again managed to show my imperfection - I was wrong! 
 I sure thought such a bug existed, but I guess it must have been a 
discussion instead of a bug report.

-- 
Eddie Bush





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Multiple forms in session [WAS: RE: how to send actionForm from one action to another action]

Posted by Andrew Hill <an...@gridnode.com>.
In my application we have a need for multiwotsit editing.

As it happens this potential trampling isnt an issue for me as I already
developed a(n evil) method for handling this sort of thing earlier (in
response to other requirements I had). Its not a technique Id recomend as a
general solution , although it works well in the particular application I am
working on.

I have an class I named the "OperationContext". Instances of
OperationContext are at heart a HashMap into which attributes can be put.
This is itself stored in the session context under a unique key. (This key
obviously has to be submitted with any request related to this
OperationContext so that it can be found again). Ive overridden the
RequestProcessor to look for my actionForms in the OperationContext first
(if there isn't an opcon or the form is request scope it just uses normal
handling). Opening a wotsit page to edit a wotsit will cause a new
OperationContext to be created. Saving the wotsit finishes the operation and
the opcon is removed.

There are several issues to consider with this sort of thing of course (many
of which are generic to anything you store in session context). Ie: The
overhead involved in making sure that the opcon id is submitted with
request, how to know when to get rid of the opcons - no problem if the user
goes through the whole editing cycle, but they can always abandon an
Operation halfway to go do something else. Theres also the issue of server
memory usage for all the stuff in the session. Not a problem in my app, but
if I was rewriting amazon.com I reckon Id be looking for a different
solution...


-----Original Message-----
From: Eddie Bush [mailto:ekbush@swbell.net]
Sent: Wednesday, December 18, 2002 12:11
To: Struts Users Mailing List
Subject: Re: Multiple forms in session [WAS: RE: how to send actionForm
from one action to another action]


Andrew Hill wrote:

>One thing Ive never understood about forms in session scope, is how does
>struts deal with the situation where there are two concurrent requests in
>the same session both of which are for the same action (and form type)?
>
They would use the same form, I'd think.  If you needed multiple
different copies you'd have to literally have different forms :-(

>As far as I can make out however, the key for a form is fixed without a way
>to differentiate different instances of the same form type. Is this
actually
>the case or havent I read the code closely enough?
>
I haven't noticed it if it's there either.  I was just looking at places
where forms are created and placed into scope because of this thread.
 It's all quite straight-forward.  You could easily trample on your form
if you're not careful.  Yet another reason to use request scoped forms.

><example>
>You have a page: editWotsits.jsp that uses the WotsitActionForm and submits
>to WotsitAction. The requirement is that the wotsit pages open in new
>windows (ie: <a target="_new"...) or frames, such that the user can be in
>the process of editing multiple wotsits at any given time. Due to some
other
>requirements (fancy workflow perhaps?) the request scope isnt an option and
>these WotsitActionForms all need to be in session scope.
></example>
>
They'd get trampled :-(  In fact, there's really not a good solution
that comes to mind.  The only single thing I see that we can do to make
using session-based forms more safe is to add the module name to the key
we use to place the forms into scope.  I'm going to go look for that bug
now - nearly certain it's there.

>-----Original Message-----
>From: Eddie Bush [mailto:ekbush@swbell.net]
>Sent: Wednesday, December 18, 2002 11:34
>To: Struts Users Mailing List
>Subject: Re: how to send actionForm from one action to another action
>
>
>It's actually a combination of the module name and the form name.  Now
>that we have modules, a strategy has to be used which allows each module
>to have forms of the same name.  The source code would definitely be the
>place to see exactly how the name is arrived at - I'd tell you, but I
>haven't looked at it since it was updated.
>
--
Eddie Bush




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Multiple forms in session [WAS: RE: how to send actionForm from one action to another action]

Posted by Eddie Bush <ek...@swbell.net>.
Andrew Hill wrote:

>One thing Ive never understood about forms in session scope, is how does
>struts deal with the situation where there are two concurrent requests in
>the same session both of which are for the same action (and form type)?
>
They would use the same form, I'd think.  If you needed multiple 
different copies you'd have to literally have different forms :-(

>As far as I can make out however, the key for a form is fixed without a way
>to differentiate different instances of the same form type. Is this actually
>the case or havent I read the code closely enough?
>
I haven't noticed it if it's there either.  I was just looking at places 
where forms are created and placed into scope because of this thread. 
 It's all quite straight-forward.  You could easily trample on your form 
if you're not careful.  Yet another reason to use request scoped forms.

><example>
>You have a page: editWotsits.jsp that uses the WotsitActionForm and submits
>to WotsitAction. The requirement is that the wotsit pages open in new
>windows (ie: <a target="_new"...) or frames, such that the user can be in
>the process of editing multiple wotsits at any given time. Due to some other
>requirements (fancy workflow perhaps?) the request scope isnt an option and
>these WotsitActionForms all need to be in session scope.
></example>
>
They'd get trampled :-(  In fact, there's really not a good solution 
that comes to mind.  The only single thing I see that we can do to make 
using session-based forms more safe is to add the module name to the key 
we use to place the forms into scope.  I'm going to go look for that bug 
now - nearly certain it's there.

>-----Original Message-----
>From: Eddie Bush [mailto:ekbush@swbell.net]
>Sent: Wednesday, December 18, 2002 11:34
>To: Struts Users Mailing List
>Subject: Re: how to send actionForm from one action to another action
>
>
>It's actually a combination of the module name and the form name.  Now
>that we have modules, a strategy has to be used which allows each module
>to have forms of the same name.  The source code would definitely be the
>place to see exactly how the name is arrived at - I'd tell you, but I
>haven't looked at it since it was updated.
>
-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>