• 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

Accessing a HashMap using Struts 2

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

I have two concerns that have been annoying me since quite some time now.

I have hashmap that was created on a page using the struts2 <s:set> tag. It looks something like this


At some point in the page, i need to get a value from the hashmap based upon a key, and i want to do it using OGNL. I dont want to iterate the map. I simply need to get a single value from the map. How am i supposed to do that without iterating?

The second problem is the following
The key is generated based upon some logic, which i store using another <s:set> tag. Something like this


I need to get a value from the hashmap using this key. And i need to display it.

How do i simply call the get function on the hashmap?

I tried this

and this

and this


The third one obviously does not work because of the nesting problem. But the same nesting logic is applicable to the second case as well, due to the manner the value attribute is handled. However none seem to work for me.


I suppose the issues are very simple. I almost feel that i get it, but somehow the solution eludes me.
Could someone please tell me what i am missing here?

Regards,
Ryan Sukale
 
ryan sukale
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok guys, i got it

I suppose i was using a different version of struts wherein using the %{} was required for the expression to be evaluated. I changed the jar files now. This is what did the job for me

<s:property value="#mymap.[#mykey2]"/>

My problem was coming because i was trying to use it in a href for a s:a tag. And without the %{} operator, the expression was not being evaluated.

So, i guess, i was right in the beginning itself. Rest of the time, it was just me making silly mistakes. :>

Regards,
Ryan Sukale
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic