Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.forum.action.util
Class Paginator

java.lang.Object
  extended by com.jivesoftware.forum.action.util.Paginator

public class Paginator
extends java.lang.Object

A class to make paging of forum content easier. Lists of threads and messages usually need to be paged - using this class from your action or view should reduce the code need for page logic.

A paginator represents a set set of pages and a way to tell what the current, previous and next pages are.

The getPages()/getPages(int) methods return a "window" of page objects. This makes it possible to easily print out a paginator of 10 pages out of a total of (for example) 279 pages. The window is intelligently computed to be around the current page.

Note, this page doesn't maintain a cursor that can be advanced - simply, this class is not an iterator. This class facilitates a paginated view of a set of items at a given point in time.


Constructor Summary
Paginator(Pageable pageable)
          Creates a Paginator object.
 
Method Summary
 boolean getNextPage()
          Returns true if there is a page of items next to the current one in the list.
 int getNextPageStart()
          Returns the starting index of the next page.
 int getNumPages()
          Returns the number of total pages in this pagniator.
 Pageable getPageable()
          Returns the underlying pageable object.
 int getPageIndex()
          Returns the index of the current page.
 Page[] getPages()
          Returns an array of viewable pages 10 items in length (at most).
 Page[] getPages(int numViewablePages)
          Returns an array of Page objects representing the pages in a set of items.
 boolean getPreviousPage()
          Returns true if there is a page of items previous to the current one in the list.
 int getPreviousPageStart()
          Returns the starting index of the previous page.
 int getRange()
          Returns the number of items per page.
 int getStart()
          Returns the starting index at the current point in the list of items.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Paginator

public Paginator(Pageable pageable)
Creates a Paginator object. Pass in an object that implements the Pageable interface - this gives the class access to collection (the items we're paginating) specific numbers like number of total items, the starting page, etc.

Parameters:
pageable - an object implementing the Pageable inteface.
Method Detail

getNumPages

public int getNumPages()
Returns the number of total pages in this pagniator. Note, getPages() returns an array of pages in the current page "window" - the length of that array will not be representative of the total number of pages. This method will return the correct total number of pages.

Returns:
the total number of pages in this paginator.

getPageable

public Pageable getPageable()
Returns the underlying pageable object. From this object you can get the result filter object.

Returns:
the underlying Pageable object.

getStart

public int getStart()
Returns the starting index at the current point in the list of items.

Returns:
the starting index at the current point in the list of items.

getRange

public int getRange()
Returns the number of items per page. This times the page index is the starting item count for a particular page.

Returns:
the number of items per page.

getPageIndex

public int getPageIndex()
Returns the index of the current page. The index is 0 based and by default it is 0.

Returns:
the index of the current page.

getPreviousPage

public boolean getPreviousPage()
Returns true if there is a page of items previous to the current one in the list.

Returns:
true if there is a page previous to the current one in the list, false otherwise.

getPreviousPageStart

public int getPreviousPageStart()
Returns the starting index of the previous page. This can be used to calculate the correct values for a previous page of items in a view. So, if the user shows 15 items per page and the current start index is 15 (page 2) then this method will return 0 (which points to page 1).

Returns:
the starting index of the prevoius page of items.

getNextPage

public boolean getNextPage()
Returns true if there is a page of items next to the current one in the list.

Returns:
true if there is a page next to the current one in the list, false otherwise.

getNextPageStart

public int getNextPageStart()
Returns the starting index of the next page. This can be used to calculate the correct values for a next page of items in a view. So, if the user shows 15 items per page and the current start index is 15 (page 2) then this method will return 30 (which points to page 3).

Returns:
the starting index of the prevoius page of items.

getPages

public Page[] getPages()
Returns an array of viewable pages 10 items in length (at most).

Returns:
an array (window) of viewable pages 10 items in length (at most).
See Also:
getPages(int)

getPages

public Page[] getPages(int numViewablePages)
Returns an array of Page objects representing the pages in a set of items. Each page knows its page number and its starting index in the list of items. A null page represents a buffer or break in the pages - this is a spot where a "..." or "--" could be entered. Example: 1 ... 5 6 7 8

Note, the numViewablePages parameter is a hint but not a hard limit on the number of pages returned. The number of pages returned will be close to that number but not exactly to make the page array look good when rendered.

Parameters:
numViewablePages - the size of the page window.
Returns:
an array of Page objects designed to display a item list paginator.

Jive Forums Project Page

Copyright © 1999-2006 Jive Software.