Class PagedListHolder<E>
- Type Parameters:
- E- the element type
- All Implemented Interfaces:
- Serializable
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".
- Since:
- 19.05.2003
- Author:
- Juergen Hoeller
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intThe default maximum number of page links.static final intThe default page size.
- 
Constructor SummaryConstructorsConstructorDescriptionCreate 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.
- 
Method SummaryModifier and TypeMethodDescriptionprotected SortDefinitionCreate a deep copy of the given sort definition, for use as state holder to compare a modified sort definition against.protected voiddoSort(List<E> source, SortDefinition sort) Actually perform sorting of the given source list, according to the given sort definition.intReturn the element index of the first element on the current page.intReturn the first page to which create a link around the current page.intReturn the element index of the last element on the current page.intReturn the last page to which create a link around the current page.intReturn the maximum number of page links to a few pages around the current one.intReturn the total number of elements in the source list.intgetPage()Return the current page number.intReturn the number of pages for the current source list.Return a sub-list representing the current page.intReturn the current page size.Return the last time the list has been fetched from the source provider.getSort()Return the sort definition for this holder.Return the source list for this holder.booleanReturn if the current page is the first one.booleanReturn if the current page is the last one.voidnextPage()Switch to next page.voidSwitch to previous page.voidresort()Resort the list if necessary, i.e.voidsetMaxLinkedPages(int maxLinkedPages) Set the maximum number of page links to a few pages around the current one.voidsetPage(int page) Set the current page number.voidsetPageSize(int pageSize) Set the current page size.voidsetSort(SortDefinition sort) Set the sort definition for this holder.voidSet the source list for this holder.
- 
Field Details- 
DEFAULT_PAGE_SIZEpublic static final int DEFAULT_PAGE_SIZEThe default page size.- See Also:
 
- 
DEFAULT_MAX_LINKED_PAGESpublic static final int DEFAULT_MAX_LINKED_PAGESThe default maximum number of page links.- See Also:
 
 
- 
- 
Constructor Details- 
PagedListHolderpublic PagedListHolder()Create a new holder instance. You'll need to set a source list to be able to use the holder.- See Also:
 
- 
PagedListHolderCreate a new holder instance with the given source list, starting with a default sort definition (with "toggleAscendingOnProperty" activated).- Parameters:
- source- the source List
- See Also:
 
- 
PagedListHolderCreate a new holder instance with the given source list.- Parameters:
- source- the source List
- sort- the SortDefinition to start with
 
 
- 
- 
Method Details- 
setSourceSet the source list for this holder.
- 
getSourceReturn the source list for this holder.
- 
getRefreshDateReturn the last time the list has been fetched from the source provider.
- 
setSortSet the sort definition for this holder. Typically an instance of MutableSortDefinition.- See Also:
 
- 
getSortReturn the sort definition for this holder.
- 
setPageSizepublic void setPageSize(int pageSize) Set the current page size. Resets the current page number if changed.Default value is 10. 
- 
getPageSizepublic int getPageSize()Return the current page size.
- 
setPagepublic void setPage(int page) Set the current page number. Page numbering starts with 0.
- 
getPagepublic int getPage()Return the current page number. Page numbering starts with 0.
- 
setMaxLinkedPagespublic void setMaxLinkedPages(int maxLinkedPages) Set the maximum number of page links to a few pages around the current one.
- 
getMaxLinkedPagespublic int getMaxLinkedPages()Return the maximum number of page links to a few pages around the current one.
- 
getPageCountpublic int getPageCount()Return the number of pages for the current source list.
- 
isFirstPagepublic boolean isFirstPage()Return if the current page is the first one.
- 
isLastPagepublic boolean isLastPage()Return if the current page is the last one.
- 
previousPagepublic void previousPage()Switch to previous page. Will stay on first page if already on first page.
- 
nextPagepublic void nextPage()Switch to next page. Will stay on last page if already on last page.
- 
getNrOfElementspublic int getNrOfElements()Return the total number of elements in the source list.
- 
getFirstElementOnPagepublic int getFirstElementOnPage()Return the element index of the first element on the current page. Element numbering starts with 0.
- 
getLastElementOnPagepublic int getLastElementOnPage()Return the element index of the last element on the current page. Element numbering starts with 0.
- 
getPageListReturn a sub-list representing the current page.
- 
getFirstLinkedPagepublic int getFirstLinkedPage()Return the first page to which create a link around the current page.
- 
getLastLinkedPagepublic int getLastLinkedPage()Return the last page to which create a link around the current page.
- 
resortpublic void resort()Resort the list if necessary, i.e. if the currentsortinstance isn't equal to the backed-upsortUsedinstance.Calls doSortto trigger actual sorting.
- 
copySortDefinitionCreate 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 resortcall.- Parameters:
- sort- the current SortDefinition object
- Returns:
- a deep copy of the SortDefinition object
- See Also:
 
- 
doSortActually 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. 
 
-