Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i get the number of items in a foreach jstl tag?

Tags:

jsp

jstl

I have the following code under javascript <script></script>:

<c:forEach items="${lifeEvents}" var="event" varStatus="loop">
        latitudes["${loop.index}"] = <c:out value="${event.place.location.latitude}"/>;
        longitudes["${loop.index}"] = <c:out value="${event.place.location.longitude}"/>;
        lastEvent = "${loop.index}";
        if("${loop.index}" > 0)
            waypointEvents["${loop.index}"] = new google.maps.LatLng(latitudes["${loop.index}"],longitudes["${loop.index}"]);
</c:forEach>

How can i know the exact number of LifeEvents that exist in the lifeEvents list? prior to running the entire loop untill the end ofc

like image 602
JoaoFilipeClementeMartins Avatar asked Jan 12 '23 03:01

JoaoFilipeClementeMartins


1 Answers

If your lifeEvents is a collection, then you can get the size of the collection using jstl fn:length

<c:out value="${fn:length(lifeEvents)}" /> <%-- size of liveEvents --%>

Make sure you have added the following taglib at the top of your page to allow the fn namespace.

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
like image 180
rakhi4110 Avatar answered Feb 05 '23 12:02

rakhi4110