How to select the first element of a set with JSTL?

Posted by Sergio del Amo on Stack Overflow See other posts from Stack Overflow or by Sergio del Amo
Published on 2009-06-16T11:25:43Z Indexed on 2010/04/16 12:03 UTC
Read the original article Hit count: 294

Filed under:
|

I managed to do it with the next code but there must be an easier way.

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


<c:if test="${fn:length(attachments) > 0}">
    <c:forEach var="attachment" items="${attachments}" varStatus="loopCount">
        <c:if test="${loopCount.count eq 1}">
         attachment.id
        </c:if>
    </c:forEach>
</c:if>

© Stack Overflow or respective owner

Related posts about jstl

Related posts about j2ee