Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2, not populating Map

 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using map syntax.
 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David, thanks for the reply, but I don't understand what you mean.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List "tests['a']" or whatever you're using for keys--at least that's what I'd try first.
 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try with a genericized map?
 
Don Blodgett
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic