2
votes

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[100]=string1
accountsMap[100]=string2
accountsMap[101]=string3
accountsMap[101]=string4
accountsMap[102]=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.

1
Hello new struts2 member... To keep things running smoothly If you could be so kind as post your comment as a solution and later accept it that would be great, or you can delete the question since there is no point in anyone else answering it. - Quaternion
@Quaternion, I couldn't figure out how to delete the question, so I've posted my earlier comment as the answer. BTW, even this (answering my own question) wasn't allowed at the time I made the comment. - Vasan

1 Answers

1
votes

Solved!

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?! :-)