aspose file tools*
The moose likes Struts and the fly likes Struts2, not populating Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2, not populating Map" Watch "Struts2, not populating Map" New topic
Author

Struts2, not populating Map

Don Blodgett
Ranch Hand

Joined: Jan 09, 2006
Posts: 61
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:

Action class:


JSP which submits to this action


Thank you for your help in this matter.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Try using map syntax.
Don Blodgett
Ranch Hand

Joined: Jan 09, 2006
Posts: 61
David, thanks for the reply, but I don't understand what you mean.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Did you try with a genericized map?
Don Blodgett
Ranch Hand

Joined: Jan 09, 2006
Posts: 61
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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!)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Struts2, not populating Map