java - Display in a tabular format by merging two lists of unequal size in jstl -


sorry if question not clear. let me explain - have 2 lists, model.list1 & model.list2 of unequal sizes. however, still need display model.list2 in such way that, list elements appear under territory column. how merge these 2 lists? somehow need iterate list2 within block marked ** **

edit: can see, list 1 has 5 entries while list 2 has 3 entries. if iterate second list within first list, each iteration of list1, getting 3 territories (please see sec1). not want..

<table> <thead>  **<tr>**   <th>user</th>   <th>title</th>   <th>role</th>   <th>territory</th>    **</tr>** </thead> <tbody> <c:foreach items="${model.list1}" var="list"> <tr> <td>${list.name} </td> <td>${list.title} </td> <td>${list.role} </td> </tr> </c:foreach>    <c:foreach items="${model.list2}" var="terr">   <td>${terr}</td>       </c:foreach>  </tbody>  </table> 

current output:

user     title  role  territory   user1    lead   lead   territory1 

desired output:

user     title  role      territory   user1    lead   lead      territory1  user2    lead2  lead2     territory2  user3    lead3  lead3     territory3  user4    lead4  lead4  user5    lead5  lead5      

sec1 - not want

user     title  role      territory   user1    lead   lead      territory1 territory2 territory3  user2    lead2   lead2    territory1 territory2 territory3  user3    lead3   lead3    territory1 territory2 territory3 

you this

<table> <c:foreach items="${ list1 }" var="item" varstatus="status1">    <tr>     <td>${ item.name }</td>      <td>       <c:if test="${ status1.index lt fn:length(list2) }">         ${ list2[status1.index].name }       </c:if>      </td>         </tr> </c:foreach> </table> 

the c:if checks, if 2nd list large enough.

related: foreach's varstatus variable


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -