A request driven paging helper for a listing already loaded into memory, exposed to templates and scripts as "paginator" via Formatter. It reads the startPos and pageSize request parameters in its constructor, slices the page out of a supplied records list, and renders a bootstrap pagination control linking back to the other pages. A companion class, SearchProperties, can be derived from it for callers that page a query instead of a list.


Properties

PropertyReturnsDescription
allPageSearchPropsList<SearchProperties>Builds a SearchProperties for every page across the whole record set, from start position zero up to the total record count in steps of the page size. Requires totalRecords and pageSize to have been set; returns an empty list otherwise.
currentPageNumintThe zero based number of the page the current start position falls on.
maxPagesintThe maximum number of pages to show links for in the rendered pagination control.
nextbooleanWhether there is a page after the current one, based on the total record count.
pageSizeIntegerThe number of records shown per page.
previousbooleanWhether there is a page before the current one.
searchPropsSearchPropertiesBuilds a SearchProperties for the current page, combining the current start position and page size, for callers that page a database query rather than an in memory list.
skipToStartbooleanWhether records() walks the supplied list forward to the current start position rather than returning it unchanged.
startIntegerThe zero based index of the first record on the current page.
totalRecordsIntegerThe total number of records matching the query, across all pages.

Methods

records(List records) · getStart() · getPageSize() · setStart(Integer start) · setPageSize(Integer pageSize) · html(String id) · pageSizeHref(int newPageSize) · setPageSizeEditable(boolean pageSizeEditable) · isPrevious() · getCurrentPageNum() · isNext() · pageHref(int pageNum) · setRecords(List records) · getTotalRecords() · setTotalRecords(Integer totalRecords) · setTotalRecords(Long totalRecords) · totalRecords(Long l) · getMaxPages() · setMaxPages(int maxPages) · isSkipToStart() · setSkipToStart(boolean skipToStart) · pageSize(int i) · start(int i) · maxPages(int i) · skipToStart(boolean b) · totalRecords(int i) · pageSizeEditable(boolean i) · totalRecords(long i) · getSearchProps() · searchProps(int start) · getAllPageSearchProps()

records(List records)

Returns: List

Stores the full record list and returns just the slice for the current page, based on the start position and page size read from the request. When skipToStart is false the full list is returned unchanged.

ParameterDescription
recordsthe full, unpaged list of records. May be null or empty

getStart()

Returns: Integer

The zero based index of the first record on the current page.

getPageSize()

Returns: Integer

The number of records shown per page.

setStart(Integer start)

Returns: void

Sets the zero based index of the first record to show.

ParameterDescription
startthe start position to use. May be null

setPageSize(Integer pageSize)

Returns: void

Sets the number of records to show per page.

ParameterDescription
pageSizethe page size to use. May be null

html(String id)

Returns: String

Renders a standard bootstrap pagination control for the current records, with links back to this page for each other page. A template can build its own control instead of calling this, if preferred. Returns null when there are no records, or when all the records fit on a single page, and an empty string when there is no current request to build page links against.

ParameterDescription
idthe HTML id to give the rendered list element. Treated as empty when null

pageSizeHref(int newPageSize)

Returns: String

Builds a URL for the current page's query string with the page size changed and the start position reset to the beginning, for a page size selector link.

ParameterDescription
newPageSizethe page size the built URL should request

setPageSizeEditable(boolean pageSizeEditable)

Returns: void

Sets whether the rendered pagination control includes a page size selector.

ParameterDescription
pageSizeEditabletrue to render a page size selector alongside the pagination links

isPrevious()

Returns: boolean

Whether there is a page before the current one.

getCurrentPageNum()

Returns: int

The zero based number of the page the current start position falls on.

isNext()

Returns: boolean

Whether there is a page after the current one, based on the total record count.

pageHref(int pageNum)

Returns: String

Builds a URL for the given page number, preserving the request's other query parameters. Returns null when there is no current request, or when the requested page starts at or past the 10000 record cutoff.

ParameterDescription
pageNumthe zero based page number to build a link for

setRecords(List records)

Returns: void

Stores the full record list without slicing it into a page. Used when the caller has already paged the records itself and only wants this paginator's rendering.

ParameterDescription
recordsthe records to store. May be null

getTotalRecords()

Returns: Integer

The total number of records matching the query, across all pages.

setTotalRecords(Integer totalRecords)

Returns: void

Sets the total number of records matching the query, across all pages.

ParameterDescription
totalRecordsthe total record count. May be null

setTotalRecords(Long totalRecords)

Returns: void

Sets the total number of records matching the query, across all pages.

ParameterDescription
totalRecordsthe total record count. May be null

totalRecords(Long l)

Returns: Paginator

Sets the total record count and returns this paginator, for chaining while building it.

ParameterDescription
lthe total record count. May be null, in which case the total is left unchanged

getMaxPages()

Returns: int

The maximum number of pages to show links for in the rendered pagination control.

setMaxPages(int maxPages)

Returns: void

Sets the maximum number of pages to show links for in the rendered pagination control.

ParameterDescription
maxPagesthe maximum number of page links to render

isSkipToStart()

Returns: boolean

Whether records() walks the supplied list forward to the current start position rather than returning it unchanged.

setSkipToStart(boolean skipToStart)

Returns: void

Sets whether records() slices out the current page from the supplied list, or returns it unchanged.

ParameterDescription
skipToStarttrue to slice out the current page

pageSize(int i)

Returns: Paginator

Sets the page size and returns this paginator, for chaining while building it.

ParameterDescription
ithe page size to use

start(int i)

Returns: Paginator

Sets the start position and returns this paginator, for chaining while building it.

ParameterDescription
ithe start position to use

maxPages(int i)

Returns: Paginator

Sets the maximum number of page links to render and returns this paginator, for chaining while building it.

ParameterDescription
ithe maximum number of page links to render

skipToStart(boolean b)

Returns: Paginator

Sets whether records() slices out the current page, and returns this paginator, for chaining while building it.

ParameterDescription
btrue to slice out the current page

totalRecords(int i)

Returns: Paginator

Sets the total record count and returns this paginator, for chaining while building it.

ParameterDescription
ithe total record count

pageSizeEditable(boolean i)

Returns: Paginator

Sets whether the rendered pagination control includes a page size selector, and returns this paginator, for chaining while building it.

ParameterDescription
itrue to render a page size selector

totalRecords(long i)

Returns: Paginator

Sets the total record count and returns this paginator, for chaining while building it.

ParameterDescription
ithe total record count

getSearchProps()

Returns: SearchProperties

Builds a SearchProperties for the current page, combining the current start position and page size, for callers that page a database query rather than an in memory list.

searchProps(int start)

Returns: SearchProperties

Builds a SearchProperties for an arbitrary start position, using the current page size.

ParameterDescription
startthe start position to use

getAllPageSearchProps()

Returns: List<SearchProperties>

Builds a SearchProperties for every page across the whole record set, from start position zero up to the total record count in steps of the page size. Requires totalRecords and pageSize to have been set; returns an empty list otherwise.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.