org.springframework.beans.support
Class PagedListHolder

Direct Known Subclasses:
RefreshablePagedListHolder

public class PagedListHolder
implements Serializable

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 that toggles the ascending value on setting the same property again is used.

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".

This class just provides support for an unmodifiable List of beans. If you need on-demand refresh because of Locale or filter changes, consider RefreshablePagedListHolder.

Author:
Juergen Hoeller
Since: 19.05.2003
See Also: getPageList(), RefreshablePagedListHolder, MutableSortDefinition

Field Summary
 final static intDEFAULT_MAX_LINKED_PAGES
           
 final static intDEFAULT_PAGE_SIZE
           

Constructor Summary
PagedListHolder()
          Create a new holder instance.
PagedListHolder(List source)
          Create a new holder instance with the given source list.

Method Summary
 intgetFirstElementOnPage()
          Return the element index of the first element on the current page.
 intgetFirstLinkedPage()
          Return the first page to which create a link around the current page.
 intgetLastElementOnPage()
          Return the element index of the last element on the current page.
 intgetLastLinkedPage()
          Return the first page to which create a link around the current page.
 intgetMaxLinkedPages()
          Return the maximum number of page links to a few pages around the current one.
 intgetNrOfElements()
          Return the total number of elements in the source list.
 intgetNrOfPages()
          Return the number of pages for the current source list.
 intgetPage()
          Return the current page number.
 ListgetPageList()
          Return a sub-list representing the current page.
 intgetPageSize()
          Return the current page size.
 DategetRefreshDate()
          Return the last time the list has been fetched from the source provider.
 SortDefinitiongetSort()
          Return the sort definition for this holder.
 ListgetSource()
          Return the source list for this holder.
 booleanisFirstPage()
          Return if the current page is the first one.
 booleanisLastPage()
          Return if the current page is the last one.
 voidnextPage()
          Switch to next page.
 voidpreviousPage()
          Switch 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.
 voidsetSource(List source)
          Set the source list for this holder.

Field Detail

DEFAULT_MAX_LINKED_PAGES

public final static int DEFAULT_MAX_LINKED_PAGES

DEFAULT_PAGE_SIZE

public final static int DEFAULT_PAGE_SIZE
Constructor Detail

PagedListHolder

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

PagedListHolder

public PagedListHolder(List source)
Create a new holder instance with the given source list.
Method Detail

getFirstElementOnPage

public int getFirstElementOnPage()
Return the element index of the first element on the current page. Element numbering starts with 0.

getFirstLinkedPage

public int getFirstLinkedPage()
Return the first page to which create a link around the current page.

getLastElementOnPage

public int getLastElementOnPage()
Return the element index of the last element on the current page. Element numbering starts with 0.

getLastLinkedPage

public int getLastLinkedPage()
Return the first page to which create a link around the current page.

getMaxLinkedPages

public int getMaxLinkedPages()
Return the maximum number of page links to a few pages around the current one.

getNrOfElements

public int getNrOfElements()
Return the total number of elements in the source list.

getNrOfPages

public int getNrOfPages()
Return the number of pages for the current source list.

getPage

public int getPage()
Return the current page number. Page numbering starts with 0.

getPageList

public List getPageList()
Return a sub-list representing the current page.

getPageSize

public int getPageSize()
Return the current page size.

getRefreshDate

public Date getRefreshDate()
Return the last time the list has been fetched from the source provider.

getSort

public SortDefinition getSort()
Return the sort definition for this holder.

getSource

public List getSource()
Return the source list for this holder.

isFirstPage

public boolean isFirstPage()
Return if the current page is the first one.

isLastPage

public boolean isLastPage()
Return if the current page is the last one.

nextPage

public void nextPage()
Switch to next page. Will stay on last page if already on last page.

previousPage

public void previousPage()
Switch to previous page. Will stay on first page if already on first page.

resort

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

setMaxLinkedPages

public void setMaxLinkedPages(int maxLinkedPages)
Set the maximum number of page links to a few pages around the current one.

setPage

public void setPage(int page)
Set the current page number. Page numbering starts with 0.

setPageSize

public void setPageSize(int pageSize)
Set the current page size. Resets the current page number if changed.

Default value is 10.


setSort

public void setSort(SortDefinition sort)
Set the sort definition for this holder. Typically an instance of MutableSortDefinition.
See Also:
MutableSortDefinition

setSource

public void setSource(List source)
Set the source list for this holder.

Association Links

to Class java.util.List

to Class org.springframework.beans.support.SortDefinition

to Class org.springframework.beans.support.SortDefinition