This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterate over a HashMap where the value is a bean

 
Steve Dambrosio
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can iterate over HashMap *values* no problem when the value is a String. However when the value is a bean I don't know how to get at the properties (the getter methods) of the bean! It seems that struts allows only property="value" or property="key". I need something like property="value, property in value object=fieldname". Can anyone help? Thanks!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...

It'd help if you included how you were trying to access the values, and potentially which version of Struts.
 
Steve Dambrosio
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts version is 1.1

I'm using the iterate tag as follows.



Remember, the *value* object is a bean. An interesting side-bar: bean:write actually renders the contents of the bean! This is because the bean has overridden the toString method with one that returns a string containing formatted contents of the instance variables with labels. However, I want just one value, not the whole bean! Thanks.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not set a value with the bean value, then access that? I don't even know how to do that, what with S1.1 being like 10 years old or something... when functionality overlaps with JSTL, you should really be using JSTL. <bean:define>, maybe?
 
Steve Dambrosio
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the prompt reply! Your post is somewhat unclear to me but I think you're saying that I might be able to define a bean, "extract" the HashMap value into the bean and then get at the fields (well, the setter methods). Sounds intriguing given that this would happen within an interate loop. I'll give it some more thought. In the mean time I decided I can change the collection in my ActionClass to be an ArrayList and populate the ArrayList from the HashMap using hashMap.values(). Still there should be an easy way to iterate through the values of a HashMap when the value is a bean! P.S. sorry about the S1.1 but it's a big (er... gigantic) corporation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic