You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jannik Nørgaard Steen <js...@digitalzone.dk> on 2000/11/24 12:21:37 UTC

logic:iterate does not work with HashMap

Hi,

we're developing a web-app currently using Struts 0.5 milestone release.
In this application we store a object in the session context that contains a
HashMap which we try to access
from a JSP. This works fine.
However when we try to iterate through the HashMap like this (contents
property contains the HashMap):

<logic:iterate id="materialItem"
name="com.smartmediatech.internet.beans.MaterialResult" property="contents">
..
..
</logic:iterate>

no materialItem bean is placed in the pageContext. This is odd because if we
use a ArrayList instead of a HashMap it works... but we need to use a
HashMap for other reasons.

We've looked in the iterate tag handler source code an cannot see why it
does not work.
Have we missed something or is this a bug ?

Med venlig hilsen/Best Regards

Jannik Nørgaard Steen



Re: logic:iterate does not work with HashMap

Posted by Jannik Nørgaard Steen <js...@digitalzone.dk>.
Hi,

we looked in the Struts source code a second time. Line 283 and 284 says:

 else if (collection instanceof Map)
     iterator = ((Map) collection).entrySet().iterator();

This gets you an iterator of the *mappings* in the Map. So each element is a
java.util.Map.Entry - right ?
The doAfterBody method just put a Map.Entry in the pageContext for each
mapping in the HashMap.
So you would acutally have to do two <struts:getProperty> to get to the
value of each mapping in the entry set - one to retrieve the Map.Entry and
one to retrieve the value of the entry.

Is this the right way to do this ?

Regards,
Jannik

----- Original Message -----
From: "Jannik Nørgaard Steen" <js...@digitalzone.dk>
To: <st...@jakarta.apache.org>
Sent: Friday, November 24, 2000 12:21 PM
Subject: logic:iterate does not work with HashMap


> Hi,
>
> we're developing a web-app currently using Struts 0.5 milestone release.
> In this application we store a object in the session context that contains
a
> HashMap which we try to access
> from a JSP. This works fine.
> However when we try to iterate through the HashMap like this (contents
> property contains the HashMap):
>
> <logic:iterate id="materialItem"
> name="com.smartmediatech.internet.beans.MaterialResult"
property="contents">
> ..
> ..
> </logic:iterate>
>
> no materialItem bean is placed in the pageContext. This is odd because if
we
> use a ArrayList instead of a HashMap it works... but we need to use a
> HashMap for other reasons.
>
> We've looked in the iterate tag handler source code an cannot see why it
> does not work.
> Have we missed something or is this a bug ?
>
> Med venlig hilsen/Best Regards
>
> Jannik Nørgaard Steen
>
>
>


RE: logic:iterate does not work with HashMap

Posted by Jon-Paul Harkin <jp...@8over8.com>.
I also have a similar problem but using a Vector instead of a HaspMap

Any feedback would be appreciated

Regards,
Jon-Paul


-----Original Message-----
From: Jannik Nørgaard Steen [mailto:js@digitalzone.dk]
Sent: 24 November 2000 11:22
To: struts-user@jakarta.apache.org
Subject: logic:iterate does not work with HashMap


Hi,

we're developing a web-app currently using Struts 0.5 milestone release.
In this application we store a object in the session context that contains a
HashMap which we try to access
from a JSP. This works fine.
However when we try to iterate through the HashMap like this (contents
property contains the HashMap):

<logic:iterate id="materialItem"
name="com.smartmediatech.internet.beans.MaterialResult" property="contents">
..
..
</logic:iterate>

no materialItem bean is placed in the pageContext. This is odd because if we
use a ArrayList instead of a HashMap it works... but we need to use a
HashMap for other reasons.

We've looked in the iterate tag handler source code an cannot see why it
does not work.
Have we missed something or is this a bug ?

Med venlig hilsen/Best Regards

Jannik Nørgaard Steen