com.interface21.util
Class PagedListHolder

java.lang.Object
  |
  +--com.interface21.util.PagedListHolder
Direct Known Subclasses:
RefreshablePagedListHolder

public class PagedListHolder
extends java.lang.Object

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.

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

Field Summary
static int DEFAULT_MAX_LINKED_PAGES
           
static int DEFAULT_PAGE_SIZE
           
 
Constructor Summary
PagedListHolder()
          Create a new holder instance.
PagedListHolder(java.util.List source)
          Create a new holder instance with the given source list.
 
Method Summary
 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 first 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 getNrOfPages()
          Return the number of pages for the current source list.
 int getPage()
          Return the current page number.
 java.util.List getPageList()
          Return a sub-list representing the current page.
 int getPageSize()
          Return the current page size.
 java.util.Date getRefreshDate()
          Return the last time the list has been fetched from the source provider.
 SortDefinition getSort()
          Return the sort definition for this holder.
 java.util.List getSource()
          Return the source list for this holder.
 void resort()
          Resort the list if necessary, i.e. if the current sort instance isn't equal to the backed-up sortUsed instance.
 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(java.util.List source)
          Set the source list for this holder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAGE_SIZE

public static final int DEFAULT_PAGE_SIZE

DEFAULT_MAX_LINKED_PAGES

public static final int DEFAULT_MAX_LINKED_PAGES
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(java.util.List source)
Create a new holder instance with the given source list.
Method Detail

setSource

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

getSource

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

getRefreshDate

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

setSort

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

getSort

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

setPageSize

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

Default value is 10.


getPageSize

public int getPageSize()
Return the current page size.

setPage

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

getPage

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

getNrOfPages

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

getNrOfElements

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

getFirstElementOnPage

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

getLastElementOnPage

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

getPageList

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

setMaxLinkedPages

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

getMaxLinkedPages

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

getFirstLinkedPage

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

getLastLinkedPage

public int getLastLinkedPage()
Return the first page to which create a link around the current 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.


Rod Johnson and Spring contributors 2001-2003.