You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by horri khalid <ho...@gmail.com> on 2007/06/15 18:07:16 UTC
two collection one iteration
Hi,
I have a logic:iterate block in my JSP file that needs to iterate over two
Collections (ArrayList) simultaneously. That is:
<td height="24" align="left" class="td_lst bld">Car</td>
<td height="24" align="left" class="td_lst bld">/km</td>
<td height="24" align="left" class="td_lst bld">/day</td>
<logic:iterate id="car" name="Cars">
<td height="24" align="left" class="td_lst bld"><bean:write
name="car" property="name"/></td>
<td height="24" align="left" class="td_lst bld"><bean:write
name="rate" property="perkm"/></td>
<td height="24" align="left" class="td_lst bld"><bean:write
name="rate" property="perday"/></td>
</logic:iterate>
Problem is, the "property" attribute in the <bean:write name="rate"
property="perkm"/> tag is in error (I put it in to try to describe what I am
trying to do.) In other words, my ActionForm class has two ArrayLists (Cars
and Rates) and I want to put a value from each in thos <td>s.
How do I code the iterate block? I can iterate over one property, but not
two. As you're no doubt aware, I'm pretty new to Struts.
--
HORRI Khalid
J2EE Developper
---------------------------------------------------------
PHONE: +(212)22897659
GSM : +(212)77763981
Re: two collection one iteration
Posted by Laurie Harper <la...@holoweb.net>.
horri khalid wrote:
> Hi,
> I have a logic:iterate block in my JSP file that needs to iterate over two
> Collections (ArrayList) simultaneously. That is:
> <td height="24" align="left" class="td_lst bld">Car</td>
> <td height="24" align="left" class="td_lst bld">/km</td>
> <td height="24" align="left" class="td_lst bld">/day</td>
> <logic:iterate id="car" name="Cars">
> <td height="24" align="left" class="td_lst bld"><bean:write
> name="car" property="name"/></td>
> <td height="24" align="left" class="td_lst bld"><bean:write
> name="rate" property="perkm"/></td>
> <td height="24" align="left" class="td_lst bld"><bean:write
> name="rate" property="perday"/></td>
> </logic:iterate>
>
> Problem is, the "property" attribute in the <bean:write name="rate"
> property="perkm"/> tag is in error (I put it in to try to describe what
> I am
> trying to do.) In other words, my ActionForm class has two ArrayLists (Cars
> and Rates) and I want to put a value from each in thos <td>s.
>
> How do I code the iterate block? I can iterate over one property, but not
> two. As you're no doubt aware, I'm pretty new to Struts.
Assuming you have a one-to-one correspondence between items in the
'cars' collection and items in the 'rates' collection, the easiest thing
would probably be to zip both collections together into a single
collection of beans encapsulating the data from cars and rates. You can
then trivially iterate the single, combined collection. Or, depending on
how your data is structured/retrieved, you may be able to just combine
the two data structures so, for example, you have properties 'name',
'perkm' and 'perday' on each 'car' bean.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org