Joe
Joe

Reputation: 11

Pagination - how to make it more dynamic

I'm trying to create dynamic page links, I currently have it like this...

  <c:forEach var="page" begin="1" end="10">
    <a href="/servletmapping/${page}">${page} </a>
  </c:forEach>

On each page there are 10 rows, thus using the above code allows you to see 100.

How can I make it more dynamic? Let say, if I had 200 rows in the DB, I wouldn't be able to go to page 11 without changing the end value... obviously thats not convienient.

Upvotes: 1

Views: 1734

Answers (1)

JB Nizet
JB Nizet

Reputation: 692231

Use <c:forEach var="page" begin="1" end="${myBean.lastPage}">

where getLastPage is defined as

public int getLastPage() {
    int result = list.size() / NUMBER_OF_ITEMS_PER_PAGE;
    if (list.size() % NUMBER_OF_ITEMS_PER_PAGE > 0) {
        result++;
    }
    return result;
}

Upvotes: 1

Related Questions