struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Musachy Barroso" <musa...@gmail.com>
Subject Re: Struts2: How to access indexed property (map) with dynamic index?
Date Thu, 25 Sep 2008 14:06:13 GMT
try: #fooMap[#item.fooId]


On Thu, Sep 25, 2008 at 9:45 AM, Keim, Markus <Markus.Keim@bca.de> wrote:

> Hello all,
>
> is it possible (and how) to access the values of an indexed property
> (a map) with the Struts2 "property" tag by providing a dynamicaly
> retrieved/calculated index?
>
> In detail:
> Let's assume that "fooMap" is a simple Map<String, String> that's
> provided by a Struts2 action. That map holds a unique key (ID)
> and a description for a property of objects of the class "Item".
> It serves as source for a "select" tag to set that property
> when adding new items.
>
>
> <s:select key="item.fooId" list="fooMap" />
>
>
> On the same (JSP) page I want to list all existing items, using
> an "iterator" tag.
> That's quite easy, as long as I output the "fooId" as a simple
> property.
>
>
> <s:iterator value="itemList" id="item">
>  <tr>
>    <td><s:property value="#item.name"/></td>
>    <td><s:property value="#item.fooId"/></td>
>  </tr>
> </s:iterator>
>
> What I want to achive is to output the "fooDescription",
> that is, the value that I would get by
>
>
> fooMap.get(item.fooId);
>
>
> I've played around with plenty variations of
>
>
> <s:iterator value="itemList" id="item">
>  <tr>
>    <td><s:property value="#item.name"/></td>
>    <td><s:property value="fooMap['%{#item.fooId}']"/></td>
>  </tr>
> </s:iterator>
>
>
> Alas to no avail so far.
> It's no problem to retrieve the "fooMap" values by providing
> a static index, for example
>
>
> <s:iterator value="itemList" id="item">
>  <tr>
>    <td><s:property value="#item.name"/></td>
>    <td><s:property value="fooMap['ID1']"/></td>
>  </tr>
> </s:iterator>
>
>
> will output the description to "ID1".
> But how can I provide the dynamicaly retrieved index
> from within the iterator?
> Any insight on this would be highly appreciated. :)
>
>
> Ciao,
>
> Markus
>
> ---------------------------------------------------------------------
> 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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message