You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alexander Jede <al...@gmx.de> on 2007/08/01 11:18:16 UTC

[S1] access values of a Map

Hallo,
me bean has a Map attribute.
Now I want to get access to the values of the Map. But I do not want
iterate throw the entire Map. In Java I would write something like:
map.get("key")
What is the best way to do this in my JSP with struts 1.3.8 ?

Thanks Alex


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


Re: [S1] access values of a Map

Posted by Jasper Floor <ja...@gmail.com>.
On 8/1/07, Alexander Jede <al...@gmx.de> wrote:
>
> hmm ok I found it in the package description of bean.
> My problem was, I searched this information in the doc of the taglib (not javadoc).
> Does this work with other tags then <bean:write /> like <logic:iterate />  ?

In general when using tags I would avoid the javadoc and go for the
taglib doc (actually  always look at the taglib reference, one stop
shop for all you tag needs ;). I believe it also works for other tags,
but don't quote me on that....unless it works.

mvg,
Jasper

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


Re: [S1] access values of a Map

Posted by Alexander Jede <al...@gmx.de>.
Hi,

Am Mittwoch, den 01.08.2007, 12:26 +0200 schrieb Jasper Floor:
...
> I believe you can access indexed properties with bean:write through
> the property attribute.
> <bean:write name="yourbeanhere" property="yourindexedpropert[0]"/>
> 
> I believe this because the struts documentation tells me so. ;)
....
hmm ok I found it in the package description of bean.
My problem was, I searched this information in the doc of the taglib (not javadoc).
Does this work with other tags then <bean:write /> like <logic:iterate />  ?

Thanks
Alex


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


Re: [S1] access values of a Map

Posted by Jasper Floor <ja...@gmail.com>.
On 8/1/07, Alexander Jede <al...@gmx.de> wrote:
> Hallo,
> me bean has a Map attribute.
> Now I want to get access to the values of the Map. But I do not want
> iterate throw the entire Map. In Java I would write something like:
> map.get("key")
> What is the best way to do this in my JSP with struts 1.3.8 ?

I believe you can access indexed properties with bean:write through
the property attribute.
<bean:write name="yourbeanhere" property="yourindexedpropert[0]"/>

I believe this because the struts documentation tells me so. ;)

Obviously you don't want [0] but something that lets you select
whatever index you want at the time. I'll leave that as an exercise
for the reader.

mvg,
Jasper

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


Re: [S1] access values of a Map

Posted by Niall Pemberton <ni...@gmail.com>.
On 8/1/07, Alexander Jede <al...@gmx.de> wrote:
> Hallo,
> me bean has a Map attribute.
> Now I want to get access to the values of the Map. But I do not want
> iterate throw the entire Map. In Java I would write something like:
> map.get("key")
> What is the best way to do this in my JSP with struts 1.3.8 ?

If you have a mapped property called "foo" and you want to access the
"bar" key value - then you can use either <c:out> JSTL tag or Struts's
<bean:write>:

<c:out value='${foo.bar}'/>
<bean:write property="foo(bar)"/>

The following might work (can't remember if it does in BeanUtils 1.7.0
- but it will in the upcoming BeanUtils 1.8.0)

<bean:write property="foo.bar"/>

Niall

> Thanks Alex

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