public class

PagedListHolder

extends Object
implements Serializable
java.lang.Object
   ↳ org.springframework.beans.support.PagedListHolder<E>

Class Overview

PagedListHolder is a simple state holder for handling lists of objects, separating them into pages. Page numbering starts with 0.

This is mainly targetted at usage in web UIs. Typically, an instance will be instantiated with a list of beans, put into the session, and exported as model. The properties can all be set/get programmatically, but the most common way will be data binding, i.e. populating the bean from request parameters. The getters will mainly be used by the view.

Supports sorting the underlying list via a SortDefinition implementation, available as property "sort". By default, a MutableSortDefinition instance will be used, toggling the ascending value on setting the same property again.

The data binding names have to be called "pageSize" and "sort.ascending", as expected by BeanWrapper. Note that the names and the nesting syntax match the respective JSTL EL expressions, like "myModelAttr.pageSize" and "myModelAttr.sort.ascending".

Summary

Constants
int DEFAULT_MAX_LINKED_PAGES
int DEFAULT_PAGE_SIZE
Public Constructors
PagedListHolder()
Create a new holder instance.
PagedListHolder(List<E> source)
Create a new holder instance with the given source list, starting with a default sort definition (with "toggleAscendingOnProperty" activated).
PagedListHolder(List<E> source, SortDefinition sort)
Create a new holder instance with the given source list.
Public Methods
int getFirstElementOnPage()
Return the element index of the first element on the current page.
int getFirstLinkedPage()
Return the first page to which create a link around the current page.
int getLastElementOnPage()
Return the element index of the last element on the current page.
int getLastLinkedPage()
Return the last page to which create a link around the current page.
int getMaxLinkedPages()
Return the maximum number of page links to a few pages around the current one.
int getNrOfElements()
Return the total number of elements in the source list.
int getPage()
Return the current page number.
int getPageCount()
Return the number of pages for the current source list.
List<E> getPageList()
Return a sub-list representing the current page.
int getPageSize()
Return the current page size.
Date getRefreshDate()
Return the last time the list has been fetched from the source provider.
SortDefinition getSort()
Return the sort definition for this holder.
List<E> getSource()
Return the source list for this holder.
boolean isFirstPage()
Return if the current page is the first one.
boolean isLastPage()
Return if the current page is the last one.
void nextPage()
Switch to next page.
void previousPage()
Switch to previous page.
void resort()
Resort the list if necessary, i.e.
void setMaxLinkedPages(int maxLinkedPages)
Set the maximum number of page links to a few pages around the current one.
void setPage(int page)
Set the current page number.
void setPageSize(int pageSize)
Set the current page size.
void setSort(SortDefinition sort)
Set the sort definition for this holder.
void setSource(List<E> source)
Set the source list for this holder.
Protected Methods
SortDefinition copySortDefinition(SortDefinition sort)
Create a deep copy of the given sort definition, for use as state holder to compare a modified sort definition against.
void doSort(List<E> source, SortDefinition sort)
Actually perform sorting of the given source list, according to the given sort definition.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEFAULT_MAX_LINKED_PAGES

Also: SpringBeans

Constant Value: 10 (0x0000000a)

public static final int DEFAULT_PAGE_SIZE

Also: SpringBeans

Constant Value: 10 (0x0000000a)

Public Constructors

public PagedListHolder ()

Also: SpringBeans

Create a new holder instance. You'll need to set a source list to be able to use the holder.

See Also

public PagedListHolder (List<E> source)

Also: SpringBeans

Create a new holder instance with the given source list, starting with a default sort definition (with "toggleAscendingOnProperty" activated).

Parameters
source the source List

public PagedListHolder (List<E> source, SortDefinition sort)

Also: SpringBeans

Create a new holder instance with the given source list.

Parameters
source the source List
sort the SortDefinition to start with

Public Methods

public int getFirstElementOnPage ()

Also: SpringBeans

Return the element index of the first element on the current page. Element numbering starts with 0.

public int getFirstLinkedPage ()

Also: SpringBeans

Return the first page to which create a link around the current page.

public int getLastElementOnPage ()

Also: SpringBeans

Return the element index of the last element on the current page. Element numbering starts with 0.

public int getLastLinkedPage ()

Also: SpringBeans

Return the last page to which create a link around the current page.

public int getMaxLinkedPages ()

Also: SpringBeans

Return the maximum number of page links to a few pages around the current one.

public int getNrOfElements ()

Also: SpringBeans

Return the total number of elements in the source list.

public int getPage ()

Also: SpringBeans

Return the current page number. Page numbering starts with 0.

public int getPageCount ()

Also: SpringBeans

Return the number of pages for the current source list.

public List<E> getPageList ()

Also: SpringBeans

Return a sub-list representing the current page.

public int getPageSize ()

Also: SpringBeans

Return the current page size.

public Date getRefreshDate ()

Also: SpringBeans

Return the last time the list has been fetched from the source provider.

public SortDefinition getSort ()

Also: SpringBeans

Return the sort definition for this holder.

public List<E> getSource ()

Also: SpringBeans

Return the source list for this holder.

public boolean isFirstPage ()

Also: SpringBeans

Return if the current page is the first one.

public boolean isLastPage ()

Also: SpringBeans

Return if the current page is the last one.

public void nextPage ()

Also: SpringBeans

Switch to next page. Will stay on last page if already on last page.

public void previousPage ()

Also: SpringBeans

Switch to previous page. Will stay on first page if already on first page.

public void resort ()

Also: SpringBeans

Resort the list if necessary, i.e. if the current sort instance isn't equal to the backed-up sortUsed instance.

Calls doSort to trigger actual sorting.

public void setMaxLinkedPages (int maxLinkedPages)

Also: SpringBeans

Set the maximum number of page links to a few pages around the current one.

public void setPage (int page)

Also: SpringBeans

Set the current page number. Page numbering starts with 0.

public void setPageSize (int pageSize)

Also: SpringBeans

Set the current page size. Resets the current page number if changed.

Default value is 10.

public void setSort (SortDefinition sort)

Also: SpringBeans

Set the sort definition for this holder. Typically an instance of MutableSortDefinition.

public void setSource (List<E> source)

Also: SpringBeans

Set the source list for this holder.

Protected Methods

protected SortDefinition copySortDefinition (SortDefinition sort)

Also: SpringBeans

Create a deep copy of the given sort definition, for use as state holder to compare a modified sort definition against.

Default implementation creates a MutableSortDefinition instance. Can be overridden in subclasses, in particular in case of custom extensions to the SortDefinition interface. Is allowed to return null, which means that no sort state will be held, triggering actual sorting for each resort call.

Parameters
sort the current SortDefinition object
Returns
  • a deep copy of the SortDefinition object

protected void doSort (List<E> source, SortDefinition sort)

Also: SpringBeans

Actually perform sorting of the given source list, according to the given sort definition.

The default implementation uses Spring's PropertyComparator. Can be overridden in subclasses.