• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Adding Dynamic rows and passing the values to Struts Action

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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 have achieved the first two requirement using javascript as below:

However I am stuck at the third point. I am also wondering if adding row and binding it to ActionClass, can be achieved without using Javascript.
If javascript has to be used, then do you see any problem with the hard coding I have used?
I am using Struts 1.2.9.
I am new to UI/web development world. Would appreciate if you can help. Thanks!!
Ranch Hand
Posts: 66
Netbeans IDE Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.":


Or I guess this post used to be on the Struts forum FAQ, but the link to the FAQ from that thread no longer works...


Just when I'm starting to think "Oh look! People are still asking questions about Struts 1.2.9! We're not too far behind the times!", I see things like this:

> Posted 9 years ago

Let nothing stop you! Not even this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic