I am implementing a simple portal using jsp and struts, the user full fill some parameters in a form and i present a table , every elements in the table are readOnly
except one , that is a input field that the user could full fill.The table is dynamic and i never know how many rows it would have. So using JSP and struts how can i deal with a dynamic number of input fields ?
For example ,the form have one drop-down list that i implement using the html:select
tag from struts taglib and in the ActionForm i have an Array that will be fullfill by the struts framework in every request. If the Array name that contains the possible values from the dropdown is "dropdown" the POST will be something like this "dropdown='value1'&dropdown='value2'"
, but i can not implement this solution to the dynamic input fields. I need help.
If you have a setter in your action form named
public void setDropDown(String[] selectedValues)
then Struts will call it with an array containing all the selected values in all the select boxes named "dropDown".
If you have a setter in your action form named
public void setDropDown(int index, String value)
then Struts will call it once for each select box named "dropDown[i]" where i is an integer identifying each of the rows (one index per row).
If you have a setter in your action form named
public void setDropDown(String key, String value)
then Struts will call it once for each select box named "dropDown(key)" where key is the a key identifying each of your rows (one key per row).
See http://struts.apache.org/1.x/struts-taglib/indexedprops.html for more details