java - JSTL foreach - how to loop from last to first -
this question has answer here:
- jstl foreach reverse order 5 answers
<c:set var="eventslastindex" value="${events.size() - 1}" /> <c:foreach items="${events}" var="event" begin="${eventslastindex}" end="0" step="-1"> ... </c:foreach>
this code throws exception: javax.servlet.jsp.jsptagexception: 'step' <= 0
but, how iterate last element?
as specified in this question;
you can use sthg this;
<c:foreach var="i" begin="0" end="10" step="1" varstatus="loop"> ... ${loop.end - + loop.begin} ... </c:foreach>
you must write foreach usual, , while getting value must decremental.
Comments
Post a Comment