0

I have this sample table in jsfiddle.net how my table should look like

The second column can have more than one row that should coincide with the original columns. I am very confused how to achieve this using jstl <c:forEach>

This is the code I have written which prints everything in the same row because i don't have any break statements for the inner foreach but I want something similar to what I have in jsfiddle

<c:forEach items="${abc.bcd }" var="abc">
<tr>
<td align="center"><c:out value="${abc.interval }" /></td>
<td><c:out value="${abc.operation}" /></td>
<td>
<c:forEach items="${abc.parts.info}" var="info">
<c:out value="${info.number}" />
<c:out value="${info.quantity}" />
<c:out value="${info.name}" />
</c:forEach>                        
</td>
</tr>
</c:forEach>
user525146
  • 3,918
  • 14
  • 60
  • 103

2 Answers2

0

I dunno how to detail the specs of how HTML based tables work, but the overall is rows within a single column isn't how it was developed to work. As the ration of rows with columns need to balance out in a matter of speaking.

If you have a column where you need the appearance of rows, your best bet it to place a new table within that column and build out the appearance of said rows within it

example:

<table>
   <tr>
     <td>
       <table>
         <tr>
           <td>Info</td>
           <td>Info</td>
           <td>Info</td>
         </tr>
       </table>
    </td>
  </tr>
</table>
chris
  • 36,115
  • 52
  • 143
  • 252
  • This one will put a table in the column. But the inner table columns woudn't align with the outer table. I want the inner table columns aligned with the outer table – user525146 Oct 02 '12 at 13:50
0

Looking at what you have constructed so far, it looks like you have a Map at abc.parts.info. If you have an ordered map, like a LinkedHashMap, you could iterate trough the map:

<c:forEach items="${abc.bcd}" var="abc">
  <tr>
    <td align="center"><c:out value="${abc.interval}" /></td>
    <td><c:out value="${abc.operation}" /></td>
    <c:forEach items="${abc.parts.info}" var="info">
      <td><c:out value="${info.value}" /></td>
    </c:forEach>                        
  </tr>
</c:forEach>

If you have an unordered map, like a HashMap, you could just access values in your map using EL (assuming your keys are strings):

<c:forEach items="${abc.bcd}" var="abc">
  <tr>
    <td align="center"><c:out value="${abc.interval}" /></td>
    <td><c:out value="${abc.operation}" /></td>
    <td><c:out value="${abc.parts.info['number']}" /></td>
    <td><c:out value="${abc.parts.info['quantity']}" /></td>
    <td><c:out value="${abc.parts.info['name']}" /></td>
  </tr>
</c:forEach>
Community
  • 1
  • 1
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102