GeeCON Prague 2014*
The moose likes Struts and the fly likes In Struts can i have more that one form on a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "In Struts can i have more that one form on a page" Watch "In Struts can i have more that one form on a page" New topic
Author

In Struts can i have more that one form on a page

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Hi,
I would like some of my pages to have more than one form allocated and therefore passed to the action class for processing. Is this possible without resonable fuss. Are there examples? I would like to have a form class associated with each table and petsistable object. Nice clean design but the front end has pages where updates are made to more that one table. Thanks for any help.
David
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4474
    
    6

You would have to use different action mappings. E.g.
<action path="action/form1" type="myAction" name="form1" >
...
<action path="action/form2" type="myAction" name="form2" >
...
Then you'd have to dispatch requests depending on the type of form received. One of the first things you might try would be a series of if statements that tests for specific instanceofs your different forms but this isn't ideal, especially if it's possible that new form types will be added in the future. But then again, DTSTTCPW and YAGNI, so if you can live with it for now...
[ April 18, 2003: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4474
    
    6

Also, your current design may seem clean and simple at first but making a form correspond to a single table/persistable object is mixing your layers and coupling the wrong ones together.
ActionForms should be more tightly coupled to the JSPs that they work with since the form is part of the view layer. Your table is part of the db layer. Your persistable object probably straddles your Model and Persistence layer.
The ActionForm should be used to relay information between the View layer and Model layer, not from the View directly to the Persistence layer. Let the Model worry about relaying the information to the appropriate Persistence layer objects.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In Struts can i have more that one form on a page