Requirement: On click of a button, have to add and delete rows in an existing table.
The row will have 4 columns - col1 is label, col2 is dropdown, col3 is text and col4 a delete button. These will be same irrespective of the number of rows added.
After user makes selection and inputs the values in the newly added row, pass these values to Action class when user submits the form.
I am using Struts 1.2.9.
I am new to UI/web development world. Would appreciate if you can help. Thanks!!
Hi! I work with someone who *just* ran into the exact same issue last week; she solved it by using indexed inputs, which are apparently a thing Struts has support for. I think we're also using Struts 1.2.9 actually; it's either that or 1.2.1, but either way, your version of Struts should have this because it was added for 1.2. It wasn't a project I was formally assigned to; I only know about it because the person who ran into it happens to also be my mom, and she asked me for advice on a few of the back end things, so I don't know everything about it, but I do know it's the tool you're looking for. You can make a dynamic list of properties in a Struts form with "Indexed Properties"; in essence you tell Struts to treat that field as a List of a sort, and the way you reference the items in that list looks similar to how you would reference an array index in java, but the behavior of the list seems to be more similar to how an ArrayList object works in java. You can add rows to the list even after the page is loaded, you can take them out, or whatever; as long as you have a property defined as an Indexed property and the inputs reference it correctly.
I'm not sure how far into the back end your role in the project goes, but for the record it is also possible to set up Struts validation with XML for fields set up that way. The validation can be tricky because the names of the properties at the various stages in the process aren't really intuitive, but it is possible!
Here's more on that from some people who are probably a little more familiar with it than "Gee, my mom's cousin's brother's uncle had to use that last week to fix a thing, and I fixed something tangentially related to it in the same project.":