struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brad A Cupit" <>
Subject RE: Iterate through a Map, OGNL Question about accessing a map with dynamic value [0]
Date Thu, 09 Oct 2008 14:04:27 GMT
From: Torsten Krah [] 
Sent: Thursday, October 09, 2008 8:27 AM
> <s:iterator value="mylist" status="status" id="list">
>	 <s:iterator value="mymap.[0]" id="listinmap"
>	</s:iterator>
> </s:iterator>

The below code should work in any JSP that has the Struts 2 tag library imported. It iterates
over a Map whose keys are of type List.
This code was inspired by [1]

<%-- begin setup tags just for this example --%>
<s:set name="list1" value="{1,2,3}"/>
<s:set name="list2" value="{4,5,6}"/>
<s:set name="myMap" value="#{#list1:'value1', #list2:'value2'}"/>
<%-- end setup tags --%>

<%-- Here are the tags you'll actually want to use --%>
<s:iterator value="myMap">
    <s:iterator id="elementInList" value="key">
        <s:property value="#elementInList"/>

'key' and 'value' will be properties of the root object on the value stack so they do not
need to be accessed with a preceeding #

'elementInList' is not a property of the root object, so it does need to be accessed with
a preceeding #


Brad Cupit
LSU - University Information Systems

View raw message