I am using struts2 in my application and have a form in a jsp which is submitted to a action class.
The number of input fields in the form can vary at runtime and hence the action class can not have fixed setter and getter for the parameters. I am trying to capture these variable number of inputs in a single action class. I want to know if its possible via Struts 2 and if it is how can i do it ? I am aware of the input field names in the form (input field names populated via iterator in the jsp form).
Note: 1) I am aware of the way to capture the form values (parameters) in the action class via the appropriate getter and setter for all form values in the action class. 2) I have gone through the model driven action as described in struts 2 http://struts.apache.org/2.3.1/docs/model-driven.html
I could not get any solution on searching and any help is appreciated.
Form population code:
<s:form action="/reports/getReport.action" cssClass="table_with_padding">
<s:iterator value="reportParamsList.items" id="paramList_item">
<tr><td><s:property value="#paramList_item.paramdesc" /></td><TD><s:textfield name="#paramList_item.paramname" /></TD></tr>
</s:iterator>
<s:submit theme="ajax" loadingText="%{getResource('SiteWide.Loading.Text')}" targets="app_area" type="button" align="left" cssClass="app_form_button" value="Submit" />
</s:form>
Use same
name
attribute for alltextfields
and a correspondinghidden
field to identify itThen in your action class declare these variables and their getter/setter
Now you can iterate over
myValue
list and get its correspondingtextfield
's value