aspose file tools*
The moose likes Struts and the fly likes Struts Form Type question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Form Type question" Watch "Struts Form Type question" New topic
Author

Struts Form Type question

Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
Ok, this is just general questions about stuff I'm hazy on and just talking about it from beginning to end "outloud" would really help I think. Pretend you're talking to a 5 yr old.

Say you have an action mapped inside your struts-config which has the following entry



And the Form that the action is referring to is here:



Now when I'm on Start.jsp (before this action is called) I have a form element with an action pointing to /main.do that has a userId element. So in my action I cast the form coming in to the type listed in the xml so I can use the getter:


Ok so lets say that on the next jsp (mainPage.jsp) there is a select box that has options populated by the userOptions from the LoadMainPageAction. The user selects an option and submits the form to a new action. So, in the new action I only need the selected option but I need the list of options on the jsp. Does the MainPageBean need to contain the list of userOptions?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Pretend you're talking to a 5 yr old.

Who's the big boy? Who's the big boy! You are! Yes you aaaarreee!
So, in the new action I only need the selected option but I need the list of options on the jsp. Does the MainPageBean need to contain the list of userOptions?

That depends on who you ask. Some people say everything on the page should be in the ActionForm. When I was doing Struts 1 I preferred to keep as much *out* of the form bean as possible; that way I was that much less tied to the Struts 1 framework--I used the ActionForm *only* for form input elements.

I've never been sure if there was a good technical argument for either method, however.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
David Newton wrote:
Who's the big boy? Who's the big boy! You are! Yes you aaaarreee!


Thanks David. I appreciate that.


I used the ActionForm *only* for form input elements.


Ok, so you would put the list on the request as an attribute and use EL on the jsp to loop options?

I have a more complicated question. I have a table with 4 columns. userOption, From date, to Date, transactionId. I would like to make it so this table has 3 or 4 rows and then there is a button that will add a row to the table should they need additional rows through javascript. I envision this as a row on the html table represents an object. Lets call it lineItem with 4 attributes to each line item and then the form actionForm contains a list of lineItems. Can actionForms contain complex objects and then the property element on the html be something like lineItem.userId? I have been searching for similar requirements without much luck.

I'll word it a different way incase I'm as confusing as I figure I am. So ideally could I take a form that normally had a bunch of properties and instead the form has only 1 object with properties on the object. Secondly how would I then make it so the form could hold a list of those objects.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

As long as the dynamically-created input elements are named correctly there's no issue with this.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
so I'm wanting to do something like the following:



Where the javascript would generate the row for the table with one columns of the selects being a list of options. The user could put any number of rows in so I'd need a list of these rows. I don't know how to create a list of rows for submitting to the action form and how to set the property in the javascript there to the correct attribute for the bean or if it's even possible.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That will not work; the JSP will not be interpreted. You'd need to build up the actual HTML.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
You mean I need to use <select> and what not for the javascript since the page is already rendered? Ok and how about the ArrayList of LineItems? How would I have an arraylist of LineItems inside the actionForm if I can't use iterate to index each parameter? If I just find out what is being rendered by the struts tag after it renders html can I just code that do you think?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts Form Type question
 
Similar Threads
How to use html:select tag in struts
why is my loginForm stopped processing the user input
Struts - got a blank page
Struts 1.3 Error messages displaying improperly on jsp
how to obtain list object from an actionform