You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by meeboo <de...@gmail.com> on 2007/04/23 19:33:18 UTC
Iterating through a map
Hey all
How do I iterate through a map? My current method returns a
LinkedHashMap<String, Movie> - the map is populated and accessed by the view
as my debugger shows, but it is never iterated through. Here's the JSP
fragment
<s:iterator value="aMovieFromEachCategory">
<p>Should iterate 12 times</p>
</s:iterator>
Thanks!
--
View this message in context: http://www.nabble.com/Iterating-through-a-map-tf3633177.html#a10145180
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Iterating through a map
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
All,
meeboo wrote:
> Just read from the WW in action book -
>
> "One of the nicest features about the iterator tag is that it can iterate
> over just about any data type that has a concept of iteration. When
> iterating over a Map, it iterates over the Set returned by Map.entrySet(),
> which is a set of Map.Entry
> objects, which in turn has the methods getKey() and getValue() to retrieve
> the associated key/value pairs."
Apologies for guessing that iterating over a Map didn't make sense (I
still think so) and would therefore not work using an iterate tag. It
looks like JSP + tag libs is finally becoming Perl ;)
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGLQs69CaO5/Lv0PARAirsAJ0cuWnyXdUhrvI/lqs7Ee7yleoAowCguAeW
cLonp8t18XDyDTLJcQ6rogk=
=CfR7
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Iterating through a map
Posted by meeboo <de...@gmail.com>.
Just read from the WW in action book -
"One of the nicest features about the iterator tag is that it can iterate
over just about any data type that has a concept of iteration. When
iterating over a Map, it iterates over the Set returned by Map.entrySet(),
which is a set of Map.Entry
objects, which in turn has the methods getKey() and getValue() to retrieve
the associated key/value pairs."
The key to retrieving the values is to use <s:property value="key"/> and
<s:property value="value"/>
Felipe Rodrigues wrote:
>
> I'm not so sure if you can iterate over a Map. Even in Plain Old Java Code
> you can't do that.
> A good solution is create a keySet or a list from Map's keys and iterate
> over that, using each object to get the Map values.
>
> Good look,
>
>
> Felipe
>
>
>
> meeboo wrote:
>>
>> Hey all
>>
>> How do I iterate through a map? My current method returns a
>> LinkedHashMap<String, Movie> - the map is populated and accessed by the
>> view as my debugger shows, but it is never iterated through. Here's the
>> JSP fragment
>>
>> <s:iterator value="aMovieFromEachCategory">
>> <p>Should iterate 12 times</p>
>> </s:iterator>
>>
>> Thanks!
>>
>
>
--
View this message in context: http://www.nabble.com/Iterating-through-a-map-tf3633177.html#a10146427
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] Re: Iterating through a map
Posted by Musachy Barroso <mu...@gmail.com>.
I will use "El Zorro" next time ;)
On 4/23/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Musachy Barroso <mu...@gmail.com> wrote:
> > name-John Galt
>
> Who is John Galt?
>
> (That's the third time I've gotten to say that,
> legitimately, in the last two weeks!!! Must be a
> resurgence in reading Rand lately or something.)
>
> d.
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"Hey you! Would you help me to carry the stone?" Pink Floyd
Re: Iterating through a map
Posted by Dave Newton <ne...@yahoo.com>.
--- Christopher Schultz wrote:
> Did you actually try this? I would be surprised it
> it worked.
I'm pretty sure iterating over maps works; I don't see
anything weird about it. It's just minor syntactic
sugar around normal map iteration.
d.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Iterating through a map
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Musachy,
Musachy Barroso wrote:
> The value attribute for the iterator tag can be either a Collection or an
> Interator.
Uh... a Map is neither a Collection nor an Iterator.
> If it is a map, then each entry is going to be a
> Map.Entryobject, with a key and a value.
Nope. Each entry in Map.entrySet() is a Map.Entry... the Map contains
only mappings that you can look up by key.
> <s:iterator id="entry" value="#@java.util.LinkedHashMap@{'name':'John
> Galt'}">
> <s:property value="key"/> - <s:property value="value"/>
> </s:iterator>
>
> should print:
>
> name-John Galt
Did you actually try this? I would be surprised it it worked.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGLQrK9CaO5/Lv0PARAvNzAJwInFJnPgevVu+NQeVSu0z7QZlhCwCdE6mG
QajOMasxCLNXU9u2Vam1GY4=
=TdH7
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: Iterating through a map
Posted by Dave Newton <ne...@yahoo.com>.
--- Musachy Barroso <mu...@gmail.com> wrote:
> name-John Galt
Who is John Galt?
(That's the third time I've gotten to say that,
legitimately, in the last two weeks!!! Must be a
resurgence in reading Rand lately or something.)
d.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Iterating through a map
Posted by Musachy Barroso <mu...@gmail.com>.
The value attribute for the iterator tag can be either a Collection or an
Interator. If it is a map, then each entry is going to be a
Map.Entryobject, with a key and a value.
<s:iterator id="entry" value="#@java.util.LinkedHashMap@{'name':'John
Galt'}">
<s:property value="key"/> - <s:property value="value"/>
</s:iterator>
should print:
name-John Galt
musachy
On 4/23/07, Felipe Rodrigues <fe...@yahoo.com.br> wrote:
>
>
> I'm not so sure if you can iterate over a Map. Even in Plain Old Java Code
> you can't do that.
> A good solution is create a keySet or a list from Map's keys and iterate
> over that, using each object to get the Map values.
>
> Good look,
>
>
> Felipe
>
>
>
> meeboo wrote:
> >
> > Hey all
> >
> > How do I iterate through a map? My current method returns a
> > LinkedHashMap<String, Movie> - the map is populated and accessed by the
> > view as my debugger shows, but it is never iterated through. Here's the
> > JSP fragment
> >
> > <s:iterator value="aMovieFromEachCategory">
> > <p>Should iterate 12 times</p>
> > </s:iterator>
> >
> > Thanks!
> >
>
> --
> View this message in context:
> http://www.nabble.com/Iterating-through-a-map-tf3633177.html#a10145984
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"Hey you! Would you help me to carry the stone?" Pink Floyd
Re: Iterating through a map
Posted by Felipe Rodrigues <fe...@yahoo.com.br>.
I'm not so sure if you can iterate over a Map. Even in Plain Old Java Code
you can't do that.
A good solution is create a keySet or a list from Map's keys and iterate
over that, using each object to get the Map values.
Good look,
Felipe
meeboo wrote:
>
> Hey all
>
> How do I iterate through a map? My current method returns a
> LinkedHashMap<String, Movie> - the map is populated and accessed by the
> view as my debugger shows, but it is never iterated through. Here's the
> JSP fragment
>
> <s:iterator value="aMovieFromEachCategory">
> <p>Should iterate 12 times</p>
> </s:iterator>
>
> Thanks!
>
--
View this message in context: http://www.nabble.com/Iterating-through-a-map-tf3633177.html#a10145984
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org