You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by JOSE L MARTINEZ-AVIAL <jl...@gmail.com> on 2010/12/14 03:29:13 UTC

Iterate through a List of Maps

Hello all, I'm trying to iterate through a List of Maps(I have a method
"public List<Map> getRecords()" in the action) using s:iterator. I can
iterate through the List without problems, but I can not get it to iterate
through the entries of the map. So far I've got this:

[..]
<s:iterator value="records" status="recordsStatus" var="record">
        <s:if test="#recordsStatus.index ==0">
            <tr>
                <td colspan="*"></td>
            </tr>
        </s:if>
        <tr>
            <s:iterator value="record.entrySet()" status="fieldStatus">
            <td>
                <s:property value="key"/>/<s:property value="value"/>
            </td>
            </s:iterator>
        </tr>
    </s:iterator>
[..]

The tag generates the

<tr></tr>

for each entry, but it is not going through the second iterator, so I
suppose I'm doing something wrong with the value attribute. Can you help me
with it?

Thanks

Jose

Re: Iterate through a List of Maps

Posted by JOSE L MARTINEZ-AVIAL <jl...@gmail.com>.
That was fast! The version is 2.1.8.1. I'm gonna try your suggestion right
now, and let you now.

Thanks

JL

2010/12/13 Steven Yang <ke...@gmail.com>

> yes try adding "#" before "record" -> "#record"
>
> and since record is a map you can iterate through it directly without
> calling entrySet()
>
> On Tue, Dec 14, 2010 at 10:36 AM, Dave Newton <da...@gmail.com>
> wrote:
>
> > What version? Early versions sometimes required a "#" before the
> > variable name when referencing vars defined by things like an iterator
> > tag.
> >
> > Dave
> >
> > On Monday, December 13, 2010, JOSE L MARTINEZ-AVIAL <jl...@gmail.com>
> > wrote:
> > > Hello all, I'm trying to iterate through a List of Maps(I have a method
> > > "public List<Map> getRecords()" in the action) using s:iterator. I can
> > > iterate through the List without problems, but I can not get it to
> > iterate
> > > through the entries of the map. So far I've got this:
> > >
> > > [..]
> > > <s:iterator value="records" status="recordsStatus" var="record">
> > >         <s:if test="#recordsStatus.index ==0">
> > >             <tr>
> > >                 <td colspan="*"></td>
> > >             </tr>
> > >         </s:if>
> > >         <tr>
> > >             <s:iterator value="record.entrySet()" status="fieldStatus">
> > >             <td>
> > >                 <s:property value="key"/>/<s:property value="value"/>
> > >             </td>
> > >             </s:iterator>
> > >         </tr>
> > >     </s:iterator>
> > > [..]
> > >
> > > The tag generates the
> > >
> > > <tr></tr>
> > >
> > > for each entry, but it is not going through the second iterator, so I
> > > suppose I'm doing something wrong with the value attribute. Can you
> help
> > me
> > > with it?
> > >
> > > Thanks
> > >
> > > Jose
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: Iterate through a List of Maps

Posted by Steven Yang <ke...@gmail.com>.
yes try adding "#" before "record" -> "#record"

and since record is a map you can iterate through it directly without
calling entrySet()

On Tue, Dec 14, 2010 at 10:36 AM, Dave Newton <da...@gmail.com> wrote:

> What version? Early versions sometimes required a "#" before the
> variable name when referencing vars defined by things like an iterator
> tag.
>
> Dave
>
> On Monday, December 13, 2010, JOSE L MARTINEZ-AVIAL <jl...@gmail.com>
> wrote:
> > Hello all, I'm trying to iterate through a List of Maps(I have a method
> > "public List<Map> getRecords()" in the action) using s:iterator. I can
> > iterate through the List without problems, but I can not get it to
> iterate
> > through the entries of the map. So far I've got this:
> >
> > [..]
> > <s:iterator value="records" status="recordsStatus" var="record">
> >         <s:if test="#recordsStatus.index ==0">
> >             <tr>
> >                 <td colspan="*"></td>
> >             </tr>
> >         </s:if>
> >         <tr>
> >             <s:iterator value="record.entrySet()" status="fieldStatus">
> >             <td>
> >                 <s:property value="key"/>/<s:property value="value"/>
> >             </td>
> >             </s:iterator>
> >         </tr>
> >     </s:iterator>
> > [..]
> >
> > The tag generates the
> >
> > <tr></tr>
> >
> > for each entry, but it is not going through the second iterator, so I
> > suppose I'm doing something wrong with the value attribute. Can you help
> me
> > with it?
> >
> > Thanks
> >
> > Jose
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Iterate through a List of Maps

Posted by Dave Newton <da...@gmail.com>.
What version? Early versions sometimes required a "#" before the
variable name when referencing vars defined by things like an iterator
tag.

Dave

On Monday, December 13, 2010, JOSE L MARTINEZ-AVIAL <jl...@gmail.com> wrote:
> Hello all, I'm trying to iterate through a List of Maps(I have a method
> "public List<Map> getRecords()" in the action) using s:iterator. I can
> iterate through the List without problems, but I can not get it to iterate
> through the entries of the map. So far I've got this:
>
> [..]
> <s:iterator value="records" status="recordsStatus" var="record">
>         <s:if test="#recordsStatus.index ==0">
>             <tr>
>                 <td colspan="*"></td>
>             </tr>
>         </s:if>
>         <tr>
>             <s:iterator value="record.entrySet()" status="fieldStatus">
>             <td>
>                 <s:property value="key"/>/<s:property value="value"/>
>             </td>
>             </s:iterator>
>         </tr>
>     </s:iterator>
> [..]
>
> The tag generates the
>
> <tr></tr>
>
> for each entry, but it is not going through the second iterator, so I
> suppose I'm doing something wrong with the value attribute. Can you help me
> with it?
>
> Thanks
>
> Jose
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org