3

I'm currently working with Struts 2 and I have this situation:

In my Action class:

private Map<String, Map<Integer, MyEntity>> map; 

public void setMap(Map<String, Map<Integer, MyEntity>> map) { 
      this.map = map; 
} 

public Map<String, Map<Integer, MyEntity>> getMap() { 
      return this.map; 
} 

In my JSP, I use an iterator to go through the map using the 'key' variable, then iterate over another list (of integers) and use this integer to go through the second map, like this: map[${key}][${myInteger}]

<s:iterator value="map" status="status"> 
  <tr> 
    <td>${status.index}</td> 
    <td>${key}</td> 
    <s:iterator value="integersList" id="myInteger"> 
      <td> 
        <s:textfield name="map[${key}][${myInteger}].myEntityAttribute" value="%{map[#attr.key][#attr.myInteger].myEntityAttribute}" id="attr_${key}_${myInteger}" theme="simple" size="10" /> 
      </td> 
    </s:iterator> 
  </tr> 
</s:iterator>

Doing this for getting the value works fine: value="%{map[#attr.key][#attr.myInteger].myEntityAttribute}"

But when I want to save the changes I can not make it work: name="map[${key}][${myInteger}].myEntityAttribute"

I don't know what I am doing wrong, or if this can not be done (I'm pretty sure there must be a way), but I'm kind of tired of trying.

I would appreciate any suggestions, really, anything that can help is welcomed.

Roman C
  • 49,761
  • 33
  • 66
  • 176
johncol
  • 584
  • 1
  • 7
  • 13

1 Answers1

0

Shortly, it's not possible with the Struts default type converter aka XWorkConverter. It's looking for the bean properties to perform their conversions.

The collection conversion is also supported and there's also a CollectionConverter that you could use to play with collections like yours.

For this purpose you should configure the converter for the corresponding collection class in the xwork-conversion.properties. It's a global properties for conversions used by struts converter. If you don't do this the Struts converter will bump your fields with ognl.ConvertionNotSupported exception. You could dismiss it via putting your own type converter for the type you convert.

Roman C
  • 49,761
  • 33
  • 66
  • 176