I have a table that is populated depending on how many cars are there. If the number of cars is 1 it will give me the 1 row (where 5 attributes are arranged in 5 columns). If the number of cars is 2 it will give me 2 rows(same 5 attributes), & so on. Now I need to split the table into as many cars are there so that there is just one row for every car. I need to do it in JSP and trying to use the tag <c:choose>
or <c:if>
, but isn't working . Please help
views:
45answers:
1
+1
A:
You need <c:forEach>
here. With it you can iterate over any List<T>
and print the <tr>
on every iteration. Assuming that you have populated a List<Car>
and put it in the EL scope as ${cars}
, here's an example:
<table>
<c:forEach items="${cars}" var="car">
<tr>
<td>${car.make}</td>
<td>${car.model}</td>
<td>${car.type}</td>
<td>${car.color}</td>
<td>${car.price}</td>
</tr>
</c:forEach>
</table>
See also:
BalusC
2010-07-13 21:12:55
@mona: Did this answer help at all?
BalusC
2010-07-23 18:57:06