JSP - How to show items in a specific order?

I need to show a list of the names of boys and girls in order. Data structure sending names to the view List<String>.

The problem is this: (e.g. boys names starting with a):

(ordered list is shown from left to right)

Aaron  Abraham   Adam   
Alen   Alex      Alexander  
..

I need to show them how (an ordered list should appear from top to bottom, then go to the second column)

Aaron     Alen   ...
Abraham   Alex
Adam      Alexander
...

Needless to say, each group changed the number of names. For example, group a may have more names than group b.

<c:forEach var="name" items="${names}">
    <div class="col-md-4">
        ${name}
   </div>
</c:forEach>
+4
source share
2 answers

, . 3

n , , n/3 , n/3

JSP 3 :

<div class="col-md-4">
    <c:forEach begin="0" end="${fn:length(names)/3}" var="name" items="${names}" varStatus="loop">
        ${name}<br/>
    </c:forEach>
</div>
<div class="col-md-4">
    <c:forEach begin="${(fn:length(names)/3) + 1}" end="${(fn:length(staffs)/3)*2}" var="name" items="${names}" varStatus="loop">
        ${name}<br/>
    </c:forEach>
</div>
<div class="col-md-4">
    <c:forEach begin="${((fn:length(names)/3)*2)+1}" var="name" items="${names}" varStatus="loop">
        ${name}<br/>
    </c:forEach>
</div>

NB: Core JSTL fn:length(names) .

 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

.

. , 4 , 3 .

+3

  • col-md-4 col-md-6, : `` `   $ {} `` `
  • , , , else, ,
  • ,
0

Source: https://habr.com/ru/post/1609231/


All Articles