struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Husted <hus...@apache.org>
Subject Re: Passing multiple ActionForms (at the same time) to an Action
Date Sat, 21 Jun 2003 12:11:47 GMT
In the parlence of HTML you *cannot* submit two forms at the same time. 
There is a single request, which will have zero or more parameters. In a 
HTML page, these parameters can be created using either the <form> tag 
or the <a> tag. When you submit a form, or click on a hyperlink, you 
create the request, along with a set of parameters. There is no way to 
change this behavior using a standard browser. (There can be only one!)

Struts can automatically create and populate a JavaBean, or ActionForm, 
from the parameters in the request. Since there is one request, and one 
set of parameters, there is one ActionForm.

If you would like to use the same set of parameters in more than one 
logical form, the simplest thing is to use a coarse-grained ActionForm 
that implements both sets of parameters. If they are all passed in the 
request, they will all be captured into the ActionForm. You can create 
one ActionForm type and then define a separate form bean to give it two 
different names (booking and search).

But, it's important to note that you do need to submit all of your 
properties from *the one and only form* that the user can submit. The 
properties do not need to be visible; they can be hidden properties.

So, if there are two forms on the page, and both must carry forward the 
properties of the other, each of the properties must be coded twice. 
Once as a visible field in its "home" form and again as a hidden field 
in the other form.

Since hidden fields can be a pain to code, I sometimes put a helper 
method on the ActionForm to spit these out for me. So, the form just 
contains a bean:write, with filter=false, and the method spits out a set 
of hidden fields. (If you are using DynaBeans, you would have to use a 
helper bean for this instead, since DynaBeans are difficult to extend 
this way.)

-Ted.


Paul McCulloch wrote:
> In the situation I describe I want two forms to be submitted to the search
> action *at the same time*- one representing the currently entered details of
> the booking & one representing the entered search criteria. The action
> should return both of these forms unmodified (to preserve data the user has
> entered) and create a bean representing the search results.
> 
> I want to use struts forms for both the booking data and search criteria so
> that when the view is created the previously entered values are preserved -
> that is one the things struts is doing for me (isn't it?)
> 
> Does that make sense?
> Is there an alternative to creating a 'super form' containg the 'real' data
> and the search criteria data?
> 
> Or do I just not get it?
> 
> thanks,
> 
> Paul
> 
> 
>>From: Ted Husted [mailto:husted@apache.org]
> 
> <snip>
> 
>>HTTP only allows you to submit a single "form". If you then need to 
>>express an incoming form as two forms on a result page, you 
>>can post the 
>>incoming form bean under another attribute name (or names). Then each 
>>form on the result page will take the properties it needs, based on 
>>which form-bean was specified for its mapping.
>>
>>-T.
>>
>>Paul McCulloch wrote:
>>
>>>Hi,
>>>
>>>I'm a struts newbie, so forgive me if this is a FAQ. Is 
>>
>>there a way to
>>
>>>submit multiple ActionForms to a single Action?
>>>
>>>I'm trying to implement search functionality on the same 
>>
>>page as the view's
>>
>>>primary function. I think an example would help...
>>>
>>>Consider a simplified ticket booking system. The booking 
>>
>>view allows the
>>
>>>user to book a number of tickets for one show. It has 
>>
>>fields for Customer,
>>
>>>Performance, number of tickets & free text remarks.
>>>
>>>The Customer & Performance fields each have an associated 
>>
>>serach button. If
>>
>>>the user presses the 'Performance Search' button then the 
>>
>>view is redrawn
>>
>>>showing the booking details already entered on the left and 
>>
>>a Performance
>>
>>>Search 'pane' on the right. 
>>>
>>>The search pane includes criteria such as 'show', 'venue', 
>>
>>'time' etc. And a
>>
>>>'search now' button. Pressing the 'search now' button 
>>
>>brings back, in the
>>
>>>search pane a list of matching performances. Clicking on a 
>>
>>performance in
>>
>>>the list populates the performance field in the booking pane.
>>>
>>>It is also possible for the user to enter remarks, whilst 
>>
>>using the search
>>
>>>function without losing those remarks.
>>>
>>>The Customer search function works in a similar manner, and 
>>
>>is displayed in
>>
>>>place of the performance search when in use.
>>>
>>>With me so far? (thanks for reading).
>>>
>>>Working under the assumption that I can't submit two forms 
>>
>>(the booking &
>>
>>>the search criteria) to a single action (the search action) 
>>
>>I have come up
>>
>>>with the following implementation:
>>>
>>>I have a single form containing all of the booking fields 
>>
>>and all of the
>>
>>>search criteria fields, with the view generating a 
>>
>>different single html
>>
>>>form definition depending on which of the search 'modes' 
>>
>>should be visible.
>>
>>>This seems to work ok.
>>>
>>>A second requirement is that these 'search functions' be 
>>
>>resueable on other
>>
>>>views. To this end I have defined the search fields in my 
>>
>>form class via a
>>
>>>map (so that I don't need to redefine the form class, just 
>>
>>to add a new
>>
>>>search criteria). I intend to wrap up the display logic in 
>>
>>some custom tags.
>>
>>>Is this is a sensible approach? Or is there a simpler way? 
>>
>>Ideally I'd like
>>
>>>my generated html to include multiple forms - one for the 
>>
>>booking and one
>>
>>>for the search, but if I do this then how do I send my 
>>
>>booking form & search
>>
>>>form to the search action (so that the page can be redrawn 
>>
>>with any modified
>>
>>>booking details preserved?
>>>
>>>Many thanks for any input.
>>>
>>>Paul
>>>
>>>
>>>**************************************
>>>Axios Email Confidentiality Footer
>>>Privileged/Confidential Information may be contained in 
>>
>>this message. If you are not the addressee indicated in this 
>>message (or responsible for delivery of the message to such 
>>person), you may not copy or deliver this message to anyone. 
>>In such case, you should destroy this message, and notify us 
>>immediately. If you or your employer does not consent to 
>>Internet email messages of this kind, please advise us 
>>immediately. Opinions, conclusions and other information 
>>expressed in this message are not given or endorsed by my 
>>Company or employer unless otherwise indicated by an 
>>authorised representative independent of this message.
>>
>>>WARNING:
>>>While Axios Systems Ltd takes steps to prevent computer 
>>
>>viruses from being transmitted via electronic mail 
>>attachments we cannot guarantee that attachments do not 
>>contain computer virus code.  You are therefore strongly 
>>advised to undertake anti virus checks prior to accessing the 
>>attachment to this electronic mail.  Axios Systems Ltd grants 
>>no warranties regarding performance use or quality of any 
>>attachment and undertakes no liability for loss or damage 
>>howsoever caused.
>>
>>>
>>>
>>---------------------------------------------------------------------
>>
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>-- 
>>Ted Husted,
>>Struts in Action <http://husted.com/struts/book.html>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


-- 
Ted Husted,
Struts in Action <http://husted.com/struts/book.html>



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


Mime
View raw message