struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bOOyah <boo...@nowhere.org>
Subject Re: How can I display a table in two columns?
Date Wed, 07 Apr 2004 12:29:23 GMT
Daniel Perry wrote:
> This works ok for that scenario, but what about if you need each item out of
> the list? eg, to iterate through a list of names:
> 
> <logic:iterate name="names" id="name">
> <tr><td><bean:write name="name"/></td></tr>
> </logic:iterate>
> 
> Gives one column....
> 
> <tr><td>name1</td></tr>
> <tr><td>name2</td></tr>
> <tr><td>name3</td></tr>
> <tr><td>name4</td></tr>
> 
> Is there an easy way to get:
> 
> <tr><td>name1</td><td>name2</td></tr>
> <tr><td>name3</td><td>name4</td></tr>

The best I can come up with (shooting from the hip) is to create an 
intermediate bean which contains two properties, the column-1 value and 
the column-2 value.  Populate each bean, put them in a list, then 
iterate over that list.  Something like this:

------------------------------------------------------------
List names = new ArrayList();
int i = 1;
while (i<=numItems) {
     TwoColBean b = new TwoColBean();
     b.setCol1("name" + i++);
     b.setCol1("name" + i++);
     this.names.add(b);
}
...
<c:forEach items="${names} var="name" >
   <tr>
     <td><c:out value="${name.col1}"/></td>
     <td><c:out value="${name.col2}"/></td>
   </tr>
</c:forEach>
------------------------------------------------------------

Surely there must be a tag lib somewhere that offers this?

-- 
bOOyah


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


Mime
View raw message