aspose file tools*
The moose likes Struts and the fly likes Setting data to more than one form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Setting data to more than one form" Watch "Setting data to more than one form" New topic
Author

Setting data to more than one form

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi all
I have a JSP Page with more than one form. Because I reuse this forms in other JSP Pages, I need more than one form and can not combine them to one form. Now I want to set the data of my Business Objects to this forms.
My question now:
How can I set the Business Objects to the forms? Of course I wane do this in the perform method of the Action class. Do I have to create the forms for this request by my own or do I have to set the Business Objects in the request and get the data back in the constructor when the forms are created:-(?
I have to use struts 1.0
Many thanks for good idees
Andr´┐Ż
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I think you have a real problem here. Multiple forms on a single page are a nightmare for users. Imagine I enter some data in a field on form A, then enter some other data in a field on form B, then click one of the two submit buttons. What happens? Only part of what I have entered is sent to the server, and the rest is silently discarded by the browser. Yuck!
Please consider generating a single "form" tag in the enclosing page, then just the form fields in the included pages. That will combine all the fields into a single form, and make all your other problems go away.
If you need to re-use the forms in other pages, wrap them in a simple page with just the form declaration, or make the generation of the form declaration optional based on a parameter or Request attribute.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

There are times when, due to the quirks of HTML, you HAVE to provide more than one form on a page, but, as Frank says, you can get in a lot of trouble unless you've made it graphically clear what gets sent and when.
In Struts, you have the Form Bean. Although Form Beans are (more or less) "models" in the model/view/controller architecture, they are not neccesarily the actual final business objects. A Form Bean may be standing as a proxy for multiple business objects. And in this way, you can have a single HTML form that's mapping to multiple objects in a way that resembles multiple forms.
You may find it useful to use the same form bean on multiple JSPs and/or to use logic tags to control what Form Bean items are displayed in a view. Then, as part of your Action processor, you can direct the Form Bean's contents to your actual Business Objects as required.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting data to more than one form
 
Similar Threads
Return List or Object[]
Strange Struts Question
Issue with multiple form beans
Return List or Object[]
automatic forward?