struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ylva Degerfeldt" <>
Subject Re: [S2]Problems using property of POJO stored in a HashMap stored in the session
Date Wed, 20 Aug 2008 09:44:29 GMT
Yes, I tried:

<s:property value = "#session.myMap[#thisValue].state"/>

but it doesn't write anything at all.

I still wonder how Struts can possibly know that the objects I've put
in my HashMap are of my InfoObject type. (I'm not so good at
reflection) When I created that HashMap, first I just did "HashMap
myMap = new HashMap()", but I tried changing that into
"Hashmap<String, InfoObject> myMap = new HashMap<String, InfoObject>()"
That didn't help though so maybe you're right, Dustin, that it's not
about type conversion, but what is the error then?

It shouldn't be so hard. - Just printing the value of a property of
the object I've received from my HashMap. What is the right way to do

I'd be really grateful if I could get some more help with this!


On Wed, Aug 20, 2008 at 6:02 AM, Dustin Pearce <> wrote:
> No, it will use reflection to find the property so typing is not the issue,
> I think.  Have you tried to just print out the value of the state property
> with a <s:property/> tag?
> On Aug 19, 2008, at 10:22 AM, Ylva Degerfeldt wrote:
>> Thanks for the tip, Dustin, but it's not working.
>> Though, I omitted the "information" part because that was only meant
>> to temporarily save a reference to the object that the Map returns -
>> an object of type InfoObject which has get- and set methods for the
>> property state. So I tried:
>> <s:if test="#session.myMap[#thisValue].state == 0">
>> but that still returns false though I know it should return true.
>> I'm wondering if it's a matter of type conversion. The get method of
>> HashMap returns an Object and I have not told Struts in any way that
>> this value should be converted to my InfoObject. Perhaps I should do
>> that, in an xml file or something? (I'm a real newbie at Struts 2 as
>> you can tell.)
>> /Ylva
>> On Tue, Aug 19, 2008 at 5:20 PM, Dustin Pearce <>
>> wrote:
>>> Everything is fine except try:
>>> <s:if test="#session.myMap[#thisValue].information.state == 0">
>>> you don't need the %{#thisValue}, its already being evaluated.  You also
>>> don't need the set, just navigate the object graph in your test.
>>> On Aug 19, 2008, at 5:43 AM, Ylva Degerfeldt wrote:
>>>> Hi,
>>>> First of all: This problem is about jsp tags. Secondly: This is a
>>>> problem which has several steps and I don't know which step I've done
>>>> wrong so I'll just show you what I've tried to do:
>>>> <s:iterator value = "#session.mySet" id = "thisValue">
>>>>   <s:set name = "information" value = "#session.myMap[%{#thisValue}]"/>
>>>>   <s:if test = "#information.state == 0">
>>>>         <s:property value = "#thisValue"/>
>>>>   </s:if>
>>>> .....
>>>> Explanation: I iterate through a Set of Strings and call each value
>>>> "thisValue".
>>>> Then I want to use "thisValue" as a key to the HashMap "myMap" for
>>>> finding an object of my "InfoObject" class. The "InfoObject" class has
>>>> a property called "state".
>>>> I want to check for the received "InfoObject" if the "state" property
>>>> == 0. If it is I want to print the value of "thisValue".
>>>> I know that the iterator tag works but it's the parts after that I'm
>>>> insecure about. About the s:set tag, I'm not sure if that's the way to
>>>> do it but I don't know how to check if it's correct when debugging.
>>>> The only thing I know is that the s:if tag is supposed to return true
>>>> and it doesn't.
>>>> I would guess it's either a matter of the syntax I used for the
>>>> "value" of the s:set tag or that Struts can't resolve that the type of
>>>> the "information" object is "InfoObject", or both.
>>>> How should I do this?
>>>> Thanks in advance!
>>>> /Ylva
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>>>> For additional commands, e-mail:
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>>> For additional commands, e-mail:
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message