JSTL limit forEach

Posted on 2006-05-16
Medium Priority
Last Modified: 2013-11-24
If im doing c:forEach and outputting the results is there a way to limit the number of results you can display ?

many thanks.
Question by:Eternal_Student
  • 2
  • 2
LVL 11

Accepted Solution

fargo earned 375 total points
ID: 16688951
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
LVL 18

Author Comment

ID: 16689089
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>

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

LVL 18

Author Comment

ID: 16689123
<c:if test="${status.count <= 3 }">

I got it ^. Thanks for the link fargo.
LVL 11

Expert Comment

ID: 16689176
good that it works. But why grade B?

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question