I am trying to populate a map from input from the user. The map is not being populated, I check this by using System.out.println(test.toString()) which is printing out {} indicating an empty map.
This is the test code that I have created in trying to figure out what is wrong:
List "tests['a']" or whatever you're using for keys--at least that's what I'd try first.
Don Blodgett
Ranch Hand
Joined: Jan 09, 2006
Posts: 61
posted
0
I tried that and I'm still having the same problem. I had thought that the bracket notation and the dot notation worked the same way with literal values, well it seems to be considering I'm getting the same result.
I found out the problem. It would seem that the reason the map was empty was because the map was being populated after the set method was called. I determined this by moving the System.out.print into the execute method and noticed the values were being populated. As a side note, it is nice to see that Struts2 auto detects the generics when populating the map.
Oh, you mean you were trying to see the value not in the action method itself, but in the setter? Yes, that wouldn't work--the action is instantiated etc. before the params interceptor is called. It's the params interceptor that sets the request parameters into the action properties--the map has to exist before it can have values put into it.
(Looking at your code I see that's what you were doing; I missed that the first time around--sorry!)