org.shept.org.springframework.beans.support
Class PagedListHolder<E>

java.lang.Object
  extended by org.shept.org.springframework.beans.support.PagedListHolder<E>
All Implemented Interfaces:
Serializable, PageableList<E>
Direct Known Subclasses:
ChoiceListHolder

public class PagedListHolder<E>
extends Object
implements Serializable, PageableList<E>

This is an extended version of the original PagedListHolder as delivered by the spring framework. The original version has implemeted a fix sorting behavior which is done in memory and cannot (easily ?) be delegated to the dataSource to be performed by a database query.

The only thing we have changed is that we made most of the local variables protected instead of private so that this behaviour can be redefined in subclasses.

added getSortUsed() getterMethod
added implements PageableList();

--- The following comment is unchanged from the original version ----
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(), org.springframework.beans.support.RefreshablePagedListHolder, TODO LIST_BINDING_NAME und getListBindingName() remove ?, Serialized Form

Field Summary
private static int DEFAULT_MAX_LINKED_PAGES
           
protected  int maxLinkedPages
           
protected  int newModelSize
           
protected  Object newModelTemplate
           
protected  boolean newPageSet
           
protected  int page
           
protected  int pageSize
           
protected  Date refreshDate
           
private static long serialVersionUID
           
protected  org.springframework.beans.support.SortDefinition sort
           
protected  org.springframework.beans.support.SortDefinition sortUsed
           
private  List<E> source
           
 
Fields inherited from interface org.shept.org.springframework.beans.support.PageableList
DEFAULT_NEW_MODEL_SIZE, DEFAULT_PAGE_SIZE, LIST_BINDING_NAME
 
Constructor Summary
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, org.springframework.beans.support.SortDefinition sort, Object newModelTemplate)
          Create a new holder instance with the given source list.
 
Method Summary
protected  Object copyModel(Object model)
          Use Springs default bean copying implementation to obtain a shallow object copy
protected  org.springframework.beans.support.SortDefinition copySortDefinition(org.springframework.beans.support.SortDefinition s)
          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> src, org.springframework.beans.support.SortDefinition s)
          Actually perform sorting of the given source list, according to the given sort definition.
protected  int getFirstElementOnPage_orig()
           
 int getFirstElementOnPage()
          Modifications in getFirstElementOnPage() and getLastElementOnPage() are a workaround for a problem in jsp implementation that getLastElementOnPage() may not return -1 (numbers below 0) which is neccessary when the list is empty (because the first element will be 0 then and the last element must be below this value otherwise an unexisting element might be indexed)
 int getFirstLinkedPage()
          Return the first page to which create a link around the current page.
protected  int getLastElementOnPage_orig()
           
 int getLastElementOnPage()
          Modifications in getFirstElementOnPage() and getLastElementOnPage() are a workaround for a problem in jsp implementation that getLastElementOnPage() may not return -1 (numbers below 0) which is neccessary when the list is empty (because the first element will be 0 then and the last element must be below this value otherwise an unexisting element might be indexed)
 int getLastLinkedPage()
          Return the last page to which create a link around the current page.
 String getListBindingName()
          return the binding name of the list
 int getMaxLinkedPages()
          Return the maximum number of page links to a few pages around the current one.
protected  List<E> getNewModels()
           
 int getNewModelSize()
          get the new model template (for creating new objects)
 Object getNewModelTemplate()
          get the new model template (for creating new objects)
 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.
 org.springframework.beans.support.SortDefinition getSort()
          Return the sort definition for this holder.
 org.springframework.beans.support.SortDefinition getSortUsed()
           
 List<E> getSource()
          Return the source list for this holder.
 boolean isEol()
          Return if the underlying resultset is completely read (always true if the resultset is not based on cursors)
 boolean isFirstPage()
          Return if the current page is the first one.
 boolean isLastPage()
          Return if the current page is the last one.
 boolean isSortNeeded()
          Added to the original implementation so we can check for changes and refresh the view conditionally..
 boolean isVisible(Integer idx)
          Return if the given element index is within the range of the currently visible Page
 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 setNewModelSize(int newModelSize)
          Set the new model template (for creating new objects)
 void setNewModelTemplate(Object newModelTemplate)
          Set a model object as a template for creating new models.
 void setPage(int page)
          Set the current page number.
 void setPageSize(int pageSize)
          Set the current page size.
 void setSort(org.springframework.beans.support.SortDefinition sort)
          Set the sort definition for this holder.
 void setSource(List<E> source)
          Set the source list for this holder.
protected  void setSourceInternal(List<E> source)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

DEFAULT_MAX_LINKED_PAGES

private static final int DEFAULT_MAX_LINKED_PAGES
See Also:
Constant Field Values

source

private List<E> source

refreshDate

protected transient Date refreshDate

sort

protected org.springframework.beans.support.SortDefinition sort

sortUsed

protected org.springframework.beans.support.SortDefinition sortUsed

pageSize

protected int pageSize

page

protected int page

newPageSet

protected transient boolean newPageSet

maxLinkedPages

protected int maxLinkedPages

newModelTemplate

protected Object newModelTemplate

newModelSize

protected int newModelSize
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.

See Also:
setSource(java.util.List)

PagedListHolder

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 - the source List
See Also:
MutableSortDefinition.setToggleAscendingOnProperty(boolean)

PagedListHolder

public PagedListHolder(List<E> source,
                       org.springframework.beans.support.SortDefinition sort,
                       Object newModelTemplate)
Create a new holder instance with the given source list.

Parameters:
source - the source List
sort - the SortDefinition to start with
Method Detail

copySortDefinition

protected org.springframework.beans.support.SortDefinition copySortDefinition(org.springframework.beans.support.SortDefinition s)
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
See Also:
MutableSortDefinition.MutableSortDefinition(SortDefinition)

doSort

protected void doSort(List<E> src,
                      org.springframework.beans.support.SortDefinition s)
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)

getFirstElementOnPage_orig

protected int getFirstElementOnPage_orig()

getFirstElementOnPage

public int getFirstElementOnPage()
Modifications in getFirstElementOnPage() and getLastElementOnPage() are a workaround for a problem in jsp implementation that getLastElementOnPage() may not return -1 (numbers below 0) which is neccessary when the list is empty (because the first element will be 0 then and the last element must be below this value otherwise an unexisting element might be indexed)

Specified by:
getFirstElementOnPage in interface PageableList<E>

getFirstLinkedPage

public int getFirstLinkedPage()
Description copied from interface: PageableList
Return the first page to which create a link around the current page.

Specified by:
getFirstLinkedPage in interface PageableList<E>

getLastElementOnPage_orig

protected int getLastElementOnPage_orig()

getLastElementOnPage

public int getLastElementOnPage()
Modifications in getFirstElementOnPage() and getLastElementOnPage() are a workaround for a problem in jsp implementation that getLastElementOnPage() may not return -1 (numbers below 0) which is neccessary when the list is empty (because the first element will be 0 then and the last element must be below this value otherwise an unexisting element might be indexed)

Specified by:
getLastElementOnPage in interface PageableList<E>

getLastLinkedPage

public int getLastLinkedPage()
Description copied from interface: PageableList
Return the last page to which create a link around the current page.

Specified by:
getLastLinkedPage in interface PageableList<E>

getMaxLinkedPages

public int getMaxLinkedPages()
Description copied from interface: PageableList
Return the maximum number of page links to a few pages around the current one.

Specified by:
getMaxLinkedPages in interface PageableList<E>

getNrOfElements

public int getNrOfElements()
Description copied from interface: PageableList
Return the total number of elements in the source list.

Specified by:
getNrOfElements in interface PageableList<E>

getPage

public int getPage()
Description copied from interface: PageableList
Return the current page number. Page numbering starts with 0.

Specified by:
getPage in interface PageableList<E>

getPageCount

public int getPageCount()
Description copied from interface: PageableList
Return the number of pages for the current source list.

Specified by:
getPageCount in interface PageableList<E>

getPageList

public List<E> getPageList()
Description copied from interface: PageableList
Return a sub-list representing the current page.

Specified by:
getPageList in interface PageableList<E>

getPageSize

public int getPageSize()
Description copied from interface: PageableList
Return the current page size.

Specified by:
getPageSize in interface PageableList<E>

getRefreshDate

public Date getRefreshDate()
Description copied from interface: PageableList
Return the last time the list has been fetched from the source provider.

Specified by:
getRefreshDate in interface PageableList<E>

getSort

public org.springframework.beans.support.SortDefinition getSort()
Description copied from interface: PageableList
Return the sort definition for this holder.

Specified by:
getSort in interface PageableList<E>

getSortUsed

public org.springframework.beans.support.SortDefinition getSortUsed()
Specified by:
getSortUsed in interface PageableList<E>

getSource

public List<E> getSource()
Description copied from interface: PageableList
Return the source list for this holder.

Specified by:
getSource in interface PageableList<E>

isFirstPage

public boolean isFirstPage()
Description copied from interface: PageableList
Return if the current page is the first one.

Specified by:
isFirstPage in interface PageableList<E>

isLastPage

public boolean isLastPage()
Description copied from interface: PageableList
Return if the current page is the last one.

Specified by:
isLastPage in interface PageableList<E>

isVisible

public boolean isVisible(Integer idx)
Description copied from interface: PageableList
Return if the given element index is within the range of the currently visible Page

Specified by:
isVisible in interface PageableList<E>

nextPage

public void nextPage()
Description copied from interface: PageableList
Switch to next page. Will stay on last page if already on last page.

Specified by:
nextPage in interface PageableList<E>

isSortNeeded

public boolean isSortNeeded()
Description copied from interface: PageableList
Added to the original implementation so we can check for changes and refresh the view conditionally..

Specified by:
isSortNeeded in interface PageableList<E>

previousPage

public void previousPage()
Description copied from interface: PageableList
Switch to previous page. Will stay on first page if already on first page.

Specified by:
previousPage in interface PageableList<E>

resort

public void resort()
Description copied from interface: PageableList
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.

Specified by:
resort in interface PageableList<E>
See Also:
#doSort

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)
Description copied from interface: PageableList
Set the current page number. Page numbering starts with 0.

Specified by:
setPage in interface PageableList<E>

setPageSize

public void setPageSize(int pageSize)
Description copied from interface: PageableList
Set the current page size. Resets the current page number if changed.

Default value is 10.

Specified by:
setPageSize in interface PageableList<E>

setSort

public void setSort(org.springframework.beans.support.SortDefinition sort)
Description copied from interface: PageableList
Set the sort definition for this holder. Typically an instance of MutableSortDefinition.

Specified by:
setSort in interface PageableList<E>
See Also:
MutableSortDefinition

setSource

public void setSource(List<E> source)
Description copied from interface: PageableList
Set the source list for this holder.

Specified by:
setSource in interface PageableList<E>

setSourceInternal

protected void setSourceInternal(List<E> source)

getNewModels

protected List<E> getNewModels()

copyModel

protected Object copyModel(Object model)
Use Springs default bean copying implementation to obtain a shallow object copy

Returns:

getNewModelTemplate

public Object getNewModelTemplate()
Description copied from interface: PageableList
get the new model template (for creating new objects)

Specified by:
getNewModelTemplate in interface PageableList<E>
Returns:
the newModelTemplate

setNewModelTemplate

public void setNewModelTemplate(Object newModelTemplate)
Set a model object as a template for creating new models.

Specified by:
setNewModelTemplate in interface PageableList<E>

getNewModelSize

public int getNewModelSize()
Description copied from interface: PageableList
get the new model template (for creating new objects)

Specified by:
getNewModelSize in interface PageableList<E>
Returns:
the newRowSize

setNewModelSize

public void setNewModelSize(int newModelSize)
Description copied from interface: PageableList
Set the new model template (for creating new objects)

Specified by:
setNewModelSize in interface PageableList<E>
Parameters:
newRowSize - the newRowSize to set

isEol

public boolean isEol()
Description copied from interface: PageableList
Return if the underlying resultset is completely read (always true if the resultset is not based on cursors)

Specified by:
isEol in interface PageableList<E>

getListBindingName

public String getListBindingName()
Description copied from interface: PageableList
return the binding name of the list

Specified by:
getListBindingName in interface PageableList<E>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.