views:

108

answers:

2

This is for a web application using struts.

I have an array of objects in my Form that gets listed in a table. A user can add/edit/delete from the table. How would I send the changed table back to the Action class?

Will I need to create a string or array of strings, and parse that into an object? Is there a way that java/struts handles objects that are to be modified in the jsp? Or does this need to be cared for in javascript?

A: 

Indexed properties in struts, apparently takes care of this.

Marcus
A: 

Struts binds the request parameters onto the ActionForm object based on name of the input.

actionFormObj.setBla(String x) { ... } matches <input name="bla"... in the form.

When you have related inputs, you can use maps or arrays for ActionForm properties and Struts is smart enough to treat them as well. See here.

Additionally, if your table contains read-only data that you switch to input when editing, you might have to deal with a lot of hidden fields in your form. If you still consider JavaScript as an option, you could create a POST request based on a JavaScript object (that you create with whatever data you wish from the table) and then use jQuery to send it. See here.

dpb