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
| Property | Returns | Description |
|---|---|---|
| allPageSearchProps | 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. |
| currentPageNum | int | The zero based number of the page the current start position falls on. |
| maxPages | int | The maximum number of pages to show links for in the rendered pagination control. |
| next | boolean | Whether there is a page after the current one, based on the total record count. |
| pageSize | Integer | The number of records shown per page. |
| previous | boolean | Whether there is a page before the current one. |
| searchProps | 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. |
| skipToStart | boolean | Whether records() walks the supplied list forward to the current start position rather than returning it unchanged. |
| start | Integer | The zero based index of the first record on the current page. |
| totalRecords | Integer | The 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.
| Parameter | Description |
|---|---|
records | the 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.
| Parameter | Description |
|---|---|
start | the start position to use. May be null |
setPageSize(Integer pageSize)
Returns: void
Sets the number of records to show per page.
| Parameter | Description |
|---|---|
pageSize | the 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.
| Parameter | Description |
|---|---|
id | the 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.
| Parameter | Description |
|---|---|
newPageSize | the page size the built URL should request |
setPageSizeEditable(boolean pageSizeEditable)
Returns: void
Sets whether the rendered pagination control includes a page size selector.
| Parameter | Description |
|---|---|
pageSizeEditable | true 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.
| Parameter | Description |
|---|---|
pageNum | the 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.
| Parameter | Description |
|---|---|
records | the 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.
| Parameter | Description |
|---|---|
totalRecords | the total record count. May be null |
setTotalRecords(Long totalRecords)
Returns: void
Sets the total number of records matching the query, across all pages.
| Parameter | Description |
|---|---|
totalRecords | the 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.
| Parameter | Description |
|---|---|
l | the 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.
| Parameter | Description |
|---|---|
maxPages | the 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.
| Parameter | Description |
|---|---|
skipToStart | true to slice out the current page |
pageSize(int i)
Returns: Paginator
Sets the page size and returns this paginator, for chaining while building it.
| Parameter | Description |
|---|---|
i | the page size to use |
start(int i)
Returns: Paginator
Sets the start position and returns this paginator, for chaining while building it.
| Parameter | Description |
|---|---|
i | the 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.
| Parameter | Description |
|---|---|
i | the 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.
| Parameter | Description |
|---|---|
b | true 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.
| Parameter | Description |
|---|---|
i | the 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.
| Parameter | Description |
|---|---|
i | true 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.
| Parameter | Description |
|---|---|
i | the 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.
| Parameter | Description |
|---|---|
start | the 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.