Answer the question
In order to leave comments, you need to log in
How can I display a valid table in JSP?
I have a matrix (List which consists of lists)
List<List<SeatDTO>> carriages = new ArrayList<List<SeatDTO>>();
for (int carriagesIterator = 0; carriagesIterator < selectedSchedule.getTrain().getCarriages(); carriagesIterator++) {
ArrayList<SeatDTO> seats = new ArrayList<SeatDTO>();
for (int seatsIterator = 0; seatsIterator < selectedSchedule.getTrain().getSeats().size(); seatsIterator++) {
seats.add(new SeatDTO(carriagesIterator, seatsIterator));
}
carriages.add(seats);
}
model.addAttribute("carriages", carriages);
<table class="table table-striped">
<tr>
<th>Carriage</th>
</tr>
<!-- Loop over and print stations -->
<c:forEach var="tmpCarriage" items="${carriages}">
<tr>
...
</tr>
</c:forEach>
</table>
Answer the question
In order to leave comments, you need to log in
You just need to add a nested loop and output some value from SeatDTO
<c:forEach var="row" items="${carriages}">
<tr>
<c:forEach var="cell" items="${row}">
<td>
<c:out value="${cell.someAccessor}">
</td>
</c:forEach>
</tr>
</c:forEach>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question