You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul McCulloch <pa...@axiossystems.com> on 2003/06/18 15:06:46 UTC

Passing multiple ActionForms to an Action

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


Re: Passing multiple ActionForms to an Action

Posted by Ted Husted <hu...@apache.org>.
Yes, it's often useful to have coarse-grained ActionForms. Often, I will 
have a single ActionForm service an entire application or application 
module.

The difference between "forms" is usually which properties are 
validated. So long as the right properties are present for a given 
"form", then the others can be null or ignored.

If you are using the validator, you can reuse ActionForm object just by 
giving them a different form bean name. Otherwise, you can have a base 
ActionForm class, and then subclass it to provide for different validate 
mehtods.

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