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

java.lang.Object
  extended by org.shept.org.springframework.beans.support.PagedListHolder<E>
      extended by org.shept.org.springframework.beans.support.ChoiceListHolder<E>
          extended by org.shept.org.springframework.beans.support.FilteredListHolder<E>
All Implemented Interfaces:
Serializable, MultiChoice<E>, PageableList<E>, Refreshable

public class FilteredListHolder<E>
extends ChoiceListHolder<E>
implements Refreshable, Serializable

FilteredListHolder is a PagedListHolder subclass with reloading capabilities. It automatically re-requests the List from the source provider, in case of Locale or filter or sort changes. It is very similar as the RefreshablePagedListHolder but in contrast it can read portions of the query from the database so large amount of data are not a problem. It also rereads the database when changes in sorting occur.

Data binding works just like with PagedListHolder. The locale can be specified in Locale's toString syntax, e.g. "locale=en_US". The filter object can be of any custom class, preferably a bean for easy data binding from a request. An instance will simply get passed through to PagedListSourceProvider.loadList. A filter property can be specified via "filter.myFilterProperty", for example.

The scenario in the controller could be: FilteredListHolder holder = request.getSession("mySessionAttr");
if (holder == null) {
holder = new FilteredListHolder();
holder.setSourceProvider(new MyAnonymousOrEmbeddedSourceProvider());
holder.setFilter(new MyAnonymousOrEmbeddedFilter());
request.getSession().setAttribute("mySessionAttr", holder);
}
holder.refresh(false); BindException ex = BindUtils.bind(request, listHolder, "myModelAttr");
return ModelAndView("myViewName", ex.getModel());

...

private class MyAnonymousOrEmbeddedSourceProvider implements DatabasePagedListSourceProvider {
public List loadList(Locale locale, Object filter) {
MyAnonymousOrEmbeddedFilter filter = (MyAnonymousOrEmbeddedFilter) filter; }

private class MyAnonymousOrEmbeddedFilter {
private String name = "";
public String getName() {
return name; public void setName(String name) {
this.name = name;
}
}

See Also:
org.springframework.beans.support.PagedListSourceProvider, LocaleEditor, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.shept.org.springframework.beans.support.ChoiceListHolder
ChoiceListHolder.ModelWithSelection
 
Field Summary
protected  boolean alwaysRefresh
           
protected  org.springframework.dao.support.DaoSupport dao
           
protected  FilterDefinition filter
           
protected  FilterDefinition filterInitial
           
protected  FilterDefinition filterUsed
           
protected  ScrollingListProviderFactory listFactory
           
protected  Boolean reloadOnSort
           
private static long serialVersionUID
           
protected  Boolean sortInMemory
           
protected  ScrollingListProvider sourceProvider
           
 
Fields inherited from class org.shept.org.springframework.beans.support.ChoiceListHolder
options, OPTIONS_BINDING_NAME, selectedAction
 
Fields inherited from class org.shept.org.springframework.beans.support.PagedListHolder
maxLinkedPages, newModelSize, newModelTemplate, newPageSet, page, pageSize, refreshDate, sort, sortUsed
 
Fields inherited from interface org.shept.org.springframework.beans.support.Refreshable
FILTER_BINDING_NAME
 
Fields inherited from interface org.shept.org.springframework.beans.support.PageableList
DEFAULT_NEW_MODEL_SIZE, DEFAULT_PAGE_SIZE, LIST_BINDING_NAME
 
Constructor Summary
FilteredListHolder()
          Create a new list holder.
FilteredListHolder(ScrollingListProvider sourceProvider)
          Create a new list holder with the given source provider.
 
Method Summary
 void clear()
          Erase the list of loaded elements from the source provider Needs to do a refresh for example to populate the list again
protected  FilterDefinition copyFilterDefinition(FilterDefinition f)
           
protected  Object copyModel(Object model)
          Use Springs default bean copying implementation to obtain a shallow object copy
protected  void doSort(List<E> source, org.springframework.beans.support.SortDefinition sort)
          Actually perform sorting of the given source list, according to the given sort definition.
 int getDefaultLoadSize()
           
 FilterDefinition getFilter()
          Return the filter that the source provider should use for loading the list.
 FilterDefinition getFilterInitial()
           
 FilterDefinition getFilterUsed()
           
 ScrollingListProviderFactory getListFactory(org.springframework.dao.support.DaoSupport dao)
           
 Boolean getReloadOnSort()
           
 Boolean getSortInMemory()
           
 ScrollingListProvider getSourceProvider()
          Return the callback class for reloading the List when necessary.
protected  void initNewModelTemplate()
           
protected  void initSourceProvider(org.springframework.dao.support.DaoSupport dao)
          Initialize the source provider with meaningful default values.
 boolean isAlwaysRefresh()
           
 boolean isEol()
          Return if the underlying resultset is completely read (always true if the resultset is not based on cursors)
protected  void loadListFirst()
           
protected  void loadListNext()
           
 void refresh()
          Reload the underlying list from the source provider if necessary (i.e.
 void refresh(org.springframework.dao.support.DaoSupport dao)
          Deprecated. 
protected  void removeNullObjects()
           
 void setAlwaysRefresh(boolean alwaysRefresh)
           
 void setDao(org.springframework.dao.support.DaoSupport dao)
           
 void setFilter(FilterDefinition filter)
          Set the filter object that the source provider should use for loading the list.
 void setFilterInitial(FilterDefinition filterInitial)
           
 void setFilterUsed(FilterDefinition filterUsed)
           
 void setListFactory(ScrollingListProviderFactory listFactory)
           
 void setPage(int page)
          Set the current page number.
 void setPageSize(int pageSize)
          Set the current page size.
 void setReloadOnSort(Boolean reloadOnSort)
           
 void setSortInMemory(Boolean sortInMemory)
           
 void setSource(List<E> source)
          Set the source list for this holder.
 void setSourceProvider(ScrollingListProvider sourceProvider)
          Set the callback class for reloading the List when necessary.
 void setUseFilter(FilterType type)
           
 String toString()
           
 
Methods inherited from class org.shept.org.springframework.beans.support.ChoiceListHolder
getOptions, getPageListWithSelection, getPageOptions, getSelectedAction, getSelectedItems, initOptions, setSelectedAction
 
Methods inherited from class org.shept.org.springframework.beans.support.PagedListHolder
copySortDefinition, getFirstElementOnPage_orig, getFirstElementOnPage, getFirstLinkedPage, getLastElementOnPage_orig, getLastElementOnPage, getLastLinkedPage, getListBindingName, getMaxLinkedPages, getNewModels, getNewModelSize, getNewModelTemplate, getNrOfElements, getPage, getPageCount, getPageList, getPageSize, getRefreshDate, getSort, getSortUsed, getSource, isFirstPage, isLastPage, isSortNeeded, isVisible, nextPage, previousPage, resort, setMaxLinkedPages, setNewModelSize, setNewModelTemplate, setSort, setSourceInternal
 
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

dao

protected transient org.springframework.dao.support.DaoSupport dao

listFactory

protected transient ScrollingListProviderFactory listFactory

sourceProvider

protected transient ScrollingListProvider sourceProvider

filter

protected FilterDefinition filter

filterUsed

protected FilterDefinition filterUsed

filterInitial

protected FilterDefinition filterInitial

sortInMemory

protected Boolean sortInMemory

reloadOnSort

protected Boolean reloadOnSort

alwaysRefresh

protected boolean alwaysRefresh
Constructor Detail

FilteredListHolder

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

See Also:
setSourceProvider(org.shept.persistence.provider.ScrollingListProvider)

FilteredListHolder

public FilteredListHolder(ScrollingListProvider sourceProvider)
Create a new list holder with the given source provider.

Method Detail

loadListFirst

protected void loadListFirst()

initNewModelTemplate

protected void initNewModelTemplate()

loadListNext

protected void loadListNext()

doSort

protected void doSort(List<E> source,
                      org.springframework.beans.support.SortDefinition sort)
Description copied from class: PagedListHolder
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.

Overrides:
doSort in class PagedListHolder<E>
See Also:
PropertyComparator.sort(java.util.List, SortDefinition)

copyModel

protected Object copyModel(Object model)
Description copied from class: PagedListHolder
Use Springs default bean copying implementation to obtain a shallow object copy

Overrides:
copyModel in class PagedListHolder<E>
Returns:

getFilter

public FilterDefinition getFilter()
Return the filter that the source provider should use for loading the list.

Specified by:
getFilter in interface Refreshable
Returns:
the current filter, or null

getSourceProvider

public ScrollingListProvider getSourceProvider()
Return the callback class for reloading the List when necessary.

Specified by:
getSourceProvider in interface Refreshable
Returns:

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>
Overrides:
isEol in class PagedListHolder<E>

clear

public void clear()
Erase the list of loaded elements from the source provider Needs to do a refresh for example to populate the list again


refresh

public void refresh()
Description copied from interface: Refreshable
Reload the underlying list from the source provider if necessary (i.e. if the locale and/or the filter has changed), and resort it.

Specified by:
refresh in interface Refreshable

refresh

@Deprecated
public void refresh(org.springframework.dao.support.DaoSupport dao)
Deprecated. 

Description copied from interface: Refreshable
Reload the underlying list from the source provider if necessary (i.e. if the locale and/or the filter has changed), and resort it.

Specified by:
refresh in interface Refreshable

removeNullObjects

protected void removeNullObjects()

setFilter

public void setFilter(FilterDefinition filter)
Set the filter object that the source provider should use for loading the list. This will typically be a bean, for easy data binding.

Specified by:
setFilter in interface Refreshable
Parameters:
filter - the filter object, or null
Throws:
Exception

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>
Overrides:
setPage in class PagedListHolder<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>
Overrides:
setPageSize in class PagedListHolder<E>

setSource

public void setSource(List<E> source)
Set the source list for this holder. In contrast to the original version we do not reset sortUsed

Specified by:
setSource in interface PageableList<E>
Overrides:
setSource in class PagedListHolder<E>

setSourceProvider

public void setSourceProvider(ScrollingListProvider sourceProvider)
Set the callback class for reloading the List when necessary. If the list is definitely not modifiable, i.e. not locale aware and no filtering, use PagedListHolder.

See Also:
PagedListHolder

getFilterUsed

public FilterDefinition getFilterUsed()

setFilterUsed

public void setFilterUsed(FilterDefinition filterUsed)

getSortInMemory

public Boolean getSortInMemory()

setSortInMemory

public void setSortInMemory(Boolean sortInMemory)

getReloadOnSort

public Boolean getReloadOnSort()

setReloadOnSort

public void setReloadOnSort(Boolean reloadOnSort)

getListFactory

public ScrollingListProviderFactory getListFactory(org.springframework.dao.support.DaoSupport dao)
Returns:
the listFactory

setListFactory

public void setListFactory(ScrollingListProviderFactory listFactory)
Parameters:
listFactory - the listFactory to set

initSourceProvider

protected void initSourceProvider(org.springframework.dao.support.DaoSupport dao)
Initialize the source provider with meaningful default values. By default the source provider is reused when it is already initialized. Paging will be requested although the capability still depends on the provider

Parameters:
force -
force -
Throws:
Exception

getDefaultLoadSize

public int getDefaultLoadSize()

getFilterInitial

public FilterDefinition getFilterInitial()
Returns:
the filterInitial

setFilterInitial

public void setFilterInitial(FilterDefinition filterInitial)
Parameters:
filterInitial - the filterInitial to set

copyFilterDefinition

protected FilterDefinition copyFilterDefinition(FilterDefinition f)

setUseFilter

public void setUseFilter(FilterType type)
Specified by:
setUseFilter in interface Refreshable

toString

public String toString()
Overrides:
toString in class PagedListHolder<E>

isAlwaysRefresh

public boolean isAlwaysRefresh()
Returns:
the alwaysRefresh

setAlwaysRefresh

public void setAlwaysRefresh(boolean alwaysRefresh)
Parameters:
alwaysRefresh - the alwaysRefresh to set

setDao

public void setDao(org.springframework.dao.support.DaoSupport dao)
Specified by:
setDao in interface Refreshable


Copyright © 2011. All Rights Reserved.