• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2: How do I access a property of a javabean stored in a HashMap?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I'm trying to learn Struts 2 and my current problem is about accessing a property of a javabean stored in a HashMap, from a jsp.

The HashMap is stored in the session. This is the code that I've tried:



The javabean that the Map returns has getState- and setState methods, so I thought the code above would work (as long as Struts can find the type of the javabean. I'm wondering whether this is the problem).
But maybe it's a syntax problem about the '#'s.

I have also tried to print out the value, using:
<s roperty value = "#session.myMap[#thisValue].state"/>

But this prints nothing at all.

I've also tried
value = "%{#session.myMap[#thisValue].state}",
value = "#session.myMap[thisValue].state"
and
value = "#session.myMap[%{thisValue}].state

but none of them prints anything.

Please help me, anyone who can!
That would be really great!

/Ylva
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If thisValue is not part of your OGNL root I think you have to do this:

value = "#session.myMap[%{#thisValue}].state
 
Ylva Degerfeldt
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply, Tom.

Now though, that issue is no longer that important since I've changed the structure of my application to using a List instead of a HashMap.

I can mention anyway that "thisValue" is the current object (a String) of an iteration through a Set and that I think I tried the syntax you mentioned before I gave up.

Thanks anyway!

/Ylva
 
reply
    Bookmark Topic Watch Topic
  • New Topic