lalartu
lalartu

Reputation: 1

How to get all of the keys for Struts 2 form when using iterator?

I have the following code block in my JSP using Struts 2 (which is inside a table which is in a form):

<s:iterator value="editableService.parameters"
status="serviceStatus">
<tr>
    <td><s:property value="name" /></td>
    <td><s:textfield name="value" label="Value" size="40" /></td>
</tr>

</s:iterator>

In my Struts2 action, how do I get all of the keys and their values when the user submits?

Since the contents of this form are dynamic per iterator, I cant have single POJO to represent form contents.

Upvotes: 0

Views: 363

Answers (1)

Roman C
Roman C

Reputation: 1

This is what you have to do, you need to write the code which is

In action:

private List<String> values = new ArrayList<>();
public List<String> getValues(){
  return values;
}

In JSP:

<s:iterator value="editableService.parameters" status="serviceStatus">
 <tr>
  <td><s:property value="name" /></td>
  <td><s:textfield name="values[%{#serviceStatus.index}]" value="%{value}" label="Value" size="40" /></td>
 </tr>
</s:iterator>

Upvotes: 0

Related Questions