Struts 2 - Type conversion problems with Map and generics
In my action class I have a Map<Long, Set<String>> attribute, named accountsMap. Lets say the key values I get are 100,101,102. I have coded my checkbox in the JSP so that the POST parameters look like this:
accountsMap=string1 accountsMap=string2 accountsMap=string3 accountsMap=string4 accountsMap=string5
So the resulting map should contain 3 entries with keys 100,101,102. The Map entry with key 100 should have a Set with 2 Strings (string1 and string2) as its value. Hope you get the idea.
I do get a populated Map in my action from struts on submitting the page. But the Map's generics information seems to have been discarded. Firstly, the keys of the Map are of type Integer and not Long as the original Map expects. Then, the Map's values are of type String; and not Set<String>. Struts is able to set these values using my setter, but when I do anything with the Map assuming key type as Long and value type as Set, I get class cast exceptions.
How do I get struts to set the correct type of values in the Map? Please help.
I did not provide a getter for the attribute because it was write-only from the page - I wouldn't have a value for it when the page loads. I added a getter (as a desperate measure) and it solved the problem! Whodathunk?! :-)