JSTL limit forEach

If im doing c:forEach and outputting the results is there a way to limit the number of results you can display ?

many thanks.
LVL 18
Eternal_StudentAsked:
Who is Participating?
 
fargoCommented:
i would prefer to limit the results in the model itself. I mean, you should pass only those "items" you wish to display.
Or you can limit it using local variables like in the following link
http://forum.java.sun.com/thread.jspa?threadID=572565&messageID=2836854
0
 
Eternal_StudentAuthor Commented:
ok, I tried something like this:

<gc:moviesList var="movies" />
            <c:forEach var="movie" items="${movies}" varStatus="status">                  
                  <c:if test="${status.count = }">
                        <a href="/sctv/movie.jsp?movieId=<c:out value="${movie.ID}" />"><c:out value="${movie.title}" /></a>
                  </c:if>                                          
            </c:forEach>

But im not sure how would set the status.count to equal 3. So it ONLY pulls out three results ?

0
 
Eternal_StudentAuthor Commented:
<c:if test="${status.count <= 3 }">

I got it ^. Thanks for the link fargo.
0
 
fargoCommented:
good that it works. But why grade B?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.