Top Description Fields Constructors Methods
org.springframework.beans.support

public Class PagedListHolder<E>

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@SuppressWarnings:serial
Type Parameters
<E>
the element type
Imports
java.io.Serializable, java.util.ArrayList, .Collections, .Date, .List, org.springframework.lang.Nullable, org.springframework.util.Assert

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

This is mainly targeted 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".

Author
Juergen Hoeller
Since
19.05.2003
See Also
getPageList(), org.springframework.beans.support.MutableSortDefinition

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_MAX_LINKED_PAGES

The default maximum number of page links.

public static final int
DEFAULT_PAGE_SIZE

The default page size.

private int
private boolean
private int
private int
private Date
private SortDefinition
private SortDefinition
private List<E>

Constructor Summary

AccessConstructor and Description
public
PagedListHolder()

Create a new holder instance.

public
PagedListHolder(List<E>
the source List
source
)

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

public
PagedListHolder(List<E>
the source List
source
,
SortDefinition
the SortDefinition to start with
sort
)

Create a new holder instance with the given source list.

Method Summary

Modifier and TypeMethod and Description
protected SortDefinition

Returns:

a deep copy of the SortDefinition object
copySortDefinition
(SortDefinition
the current SortDefinition object
sort
)

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

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

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

public int
getFirstElementOnPage()

Return the element index of the first element on the current page.

public int
getFirstLinkedPage()

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

public int
getLastElementOnPage()

Return the element index of the last element on the current page.

public int
getLastLinkedPage()

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

public int
getMaxLinkedPages()

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

public int
getNrOfElements()

Return the total number of elements in the source list.

public int
getPage()

Return the current page number.

public int
getPageCount()

Return the number of pages for the current source list.

public List<E>
getPageList()

Return a sub-list representing the current page.

public int
getPageSize()

Return the current page size.

public Date
getRefreshDate()

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

public SortDefinition
getSort()

Return the sort definition for this holder.

public List<E>
getSource()

Return the source list for this holder.

public boolean
isFirstPage()

Return if the current page is the first one.

public boolean
isLastPage()

Return if the current page is the last one.

public void
nextPage()

Switch to next page.

public void
previousPage()

Switch to previous page.

public void
resort()

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

public void
setMaxLinkedPages(int maxLinkedPages)

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

public void
setPage(int page)

Set the current page number.

public void
setPageSize(int pageSize)

Set the current page size.

public void
setSort(SortDefinition sort)

Set the sort definition for this holder.

public void
setSource(List<E> source)

Set the source list for this holder.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_MAX_LINKED_PAGESback to summary
public static final int DEFAULT_MAX_LINKED_PAGES

The default maximum number of page links.

DEFAULT_PAGE_SIZEback to summary
public static final int DEFAULT_PAGE_SIZE

The default page size.

maxLinkedPagesback to summary
private int maxLinkedPages
newPageSetback to summary
private boolean newPageSet
pageback to summary
private int page
pageSizeback to summary
private int pageSize
refreshDateback to summary
private Date refreshDate
Annotations
@Nullable
sortback to summary
private SortDefinition sort
Annotations
@Nullable
sortUsedback to summary
private SortDefinition sortUsed
Annotations
@Nullable
sourceback to summary
private List<E> source

Constructor Detail

PagedListHolderback to summary
public PagedListHolder()

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

See Also
setSource
PagedListHolderback to summary
public PagedListHolder(List<E> source)

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

Parameters
source:List<E>

the source List

See Also
MutableSortDefinition#setToggleAscendingOnProperty
PagedListHolderback to summary
public PagedListHolder(List<E> source, SortDefinition sort)

Create a new holder instance with the given source list.

Parameters
source:List<E>

the source List

sort:SortDefinition

the SortDefinition to start with

Method Detail

copySortDefinitionback to summary
protected 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.

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:SortDefinition

the current SortDefinition object

Returns:SortDefinition

a deep copy of the SortDefinition object

See Also
MutableSortDefinition#MutableSortDefinition(SortDefinition)
doSortback to summary
protected void doSort(List<E> source, SortDefinition sort)

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.

See Also
PropertyComparator#sort(java.util.List, SortDefinition)
getFirstElementOnPageback to summary
public int getFirstElementOnPage()

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

getFirstLinkedPageback to summary
public int getFirstLinkedPage()

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

getLastElementOnPageback to summary
public int getLastElementOnPage()

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

getLastLinkedPageback to summary
public int getLastLinkedPage()

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

getMaxLinkedPagesback to summary
public int getMaxLinkedPages()

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

getNrOfElementsback to summary
public int getNrOfElements()

Return the total number of elements in the source list.

getPageback to summary
public int getPage()

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

getPageCountback to summary
public int getPageCount()

Return the number of pages for the current source list.

getPageListback to summary
public List<E> getPageList()

Return a sub-list representing the current page.

getPageSizeback to summary
public int getPageSize()

Return the current page size.

getRefreshDateback to summary
public Date getRefreshDate()

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

Annotations
@Nullable
getSortback to summary
public SortDefinition getSort()

Return the sort definition for this holder.

Annotations
@Nullable
getSourceback to summary
public List<E> getSource()

Return the source list for this holder.

isFirstPageback to summary
public boolean isFirstPage()

Return if the current page is the first one.

isLastPageback to summary
public boolean isLastPage()

Return if the current page is the last one.

nextPageback to summary
public void nextPage()

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

previousPageback to summary
public void previousPage()

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

resortback to summary
public void resort()

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.

See Also
doSort
setMaxLinkedPagesback to summary
public void setMaxLinkedPages(int maxLinkedPages)

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

setPageback to summary
public void setPage(int page)

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

setPageSizeback to summary
public void setPageSize(int pageSize)

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

Default value is 10.

setSortback to summary
public void setSort(SortDefinition sort)

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

See Also
org.springframework.beans.support.MutableSortDefinition
setSourceback to summary
public void setSource(List<E> source)

Set the source list for this holder.