Using JSTL’s forEach tag, is it possible to iterate in reverse order?
Using JSTL’s forEach tag, is it possible to iterate in reverse order?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you are using
forEachto create an integer loop, you can go forward or backward, but it requires some work. It turns out you cannot do this, for example:because the spec requires the step is positive. But you can always loop in forward order and then use
<c:varto convert the incrementing number into a decrementing number:However, when you are doing a
forEachover a Collection of any sort, I am not aware of any way to have the objects in reverse order. At least, not without first sorting the elements into reverse order and then usingforEach.I have successfully navigated a
forEachloop in a desired order by doing something like the following in a JSP:With a suitable Comparator, you can loop over the items in any desired order. This works. But I am not aware of a way to say, very simply, iterate in reverse order the collection provided.