I have a event object, inside there is a Map
, the ObjectA
is the label, and the list
I made it work after the following change.
<s:iterator value="event.planMap" status="mStat" >
<h4>Plan Type: <s:property value='key' /></h4>
<table id="plan">
<s:iterator value="value.details" status="stat">
<tr>
<td><s:textfield id="name" name="event.planMap['%{key}'].details[%{#stat.index}].name" /></td>
<td><s:textfield id="text" name="event.planMap['%{key}'].details[%{#stat.index}].text" /></td>
<td><s:textfield id="contact" name="event.planMap['%{key}].details[%{#stat.index}].contact" /></td>
</tr>
</s:iterator>
The Struts can access indexed properties of the action bean, such as List
, Map
, etc., but it's required that the element class should be a Java Bean like Map<ObjectA, ObjectC>
, where ObjectC
wraps List<ObjectB>
.
Then use Struts type conversion to populate the indexed property like in this answer How to get updated list values from JSP in my action.
Indexing a collection by a property of that collection
It is also possible to obtain a unique element of a collection by passing the value of a given property of that element. By default, the property of the element of the collection is determined in
Class-conversion.properties
usingKeyProperty_xxx=yyy
, wherexxx
is the property of the bean Class that returns the collection andyyy
is the property of the collection element that we want to index on.For an example, see the following two classes:
MyAction.java
/** * @return a Collection of Foo objects */ public Collection getFooCollection() { return foo; }
Foo.java
/** * @return a unique identifier */ public Long getId() { return id; }