Andrew Tomaka wrote the following on 7/18/2005 2:13 PM:

I have a form which allows users to add a dynamic amount of rows (via
a button that says "Add Row") and then submit the form with as little
or many rows as they wish.  Can a form bean be setup using collections
instead of other object types?  What is the proper way to handle a
dynamic amount of the same data coming in to a Action?

I think to set this up where the user can add as many as they wish you'll have to do some DHTML stuff where you will be writing out the new elements using javascript. You'll probably have to keep track of what's in the currentDiv and append to it when they click "add new"

You'll need a counter of the 'currentIndex' and you'll end up writing javascript to write to a div that will make the elements like...

write( currentDivContents + "<br/><html:text propety='yourList["+curIndex+"].firstName'/>");

Of course make sure for your "yourList" that you use an approach like

http://wiki.apache.org/struts/StrutsCatalogLazyList

An easier approach might be to only allow them to enter a fixed amount at a time, say five or so. After they submit they could enter more. This would cut down on the amount of javascript.

And yes in either scenario you set up your ActionForm to use a property of type List that would hold your Collection of beans.

--
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to