tags:

views:

24

answers:

1

Hi everyone,

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

<s:set var="mymap" value="#request.mymap"/>

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.

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

<s:set var="mykey" value="1">

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 <s:property value="#mymap[#mykey]"/>

and this <s:property value="#mymap[%{#mykey}]"/>

and this <s:property value="%{#mymap[%{#mykey}}]"/>

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.

The issue here is that my key is unknown. It is a dynamically generated string based upon some pattern. I need to access the object stored in the hashmap using this dynamic key. And due to the inability of nesting ognl, i am in a fix.

I suppose the issue is 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?

A: 

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 being silly. :>

Ryan Sukale