• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding Dynamic rows and passing the values to Struts Action

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
3
Netbeans IDE Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.":

http://www.jajakarta.org/struts/struts1.2/documentation/ja/target/faqs/indexedprops.html
http://www.developer.com/java/ent/article.php/2233591/Succeeding-With-Struts-Indexed-Properties-and-Beans-as-Properties.htm

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...

https://coderanch.com/t/55172/Struts/Indexed-Properties

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

 
reply
    Bookmark Topic Watch Topic
  • New Topic