Package org.primefaces.model
Class LazyDataModel<T>
java.lang.Object
javax.faces.model.DataModel<T>
org.primefaces.model.LazyDataModel<T>
- Type Parameters:
T- The model class.
- All Implemented Interfaces:
Serializable,Iterable<T>,SelectableDataModel<T>
- Direct Known Subclasses:
DefaultLazyDataModel,JPALazyDataModel
public abstract class LazyDataModel<T>
extends javax.faces.model.DataModel<T>
implements SelectableDataModel<T>, Serializable
DataModel to deal with huge datasets with by lazy loading, page by page.
As long
DataModel is not serializable,
see ...,
do no extend from ListDataModel
see #7699- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFor serialization onlyLazyDataModel(javax.faces.convert.Converter<T> rowKeyConverter) This constructor allows to skip the implementation ofgetRowData(java.lang.String)andgetRowKey(java.lang.Object), when selection is used. -
Method Summary
Modifier and TypeMethodDescriptionabstract intcount(Map<String, FilterMeta> filterBy) Counts the all available data for the given filters.protected StringgetMessage(String msg) intintgetRowData(String rowKey) intprotected StringgetRowKeyFromConverter(T object) booleaniterator()Loads the data for the given parameters.Loads a single row for the rowIndex provided.protected intrecalculateFirst(int first, int pageSize, int rowCount) Recalculatesfirst, see #1921.voidsetPageSize(int pageSize) voidsetRowCount(int rowCount) voidsetRowIndex(int rowIndex) voidsetWrappedData(Object list) Methods inherited from class javax.faces.model.DataModel
addDataModelListener, getDataModelListeners, removeDataModelListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
rowKeyConverter
-
-
Constructor Details
-
LazyDataModel
public LazyDataModel()For serialization only -
LazyDataModel
This constructor allows to skip the implementation ofgetRowData(java.lang.String)andgetRowKey(java.lang.Object), when selection is used.- Parameters:
rowKeyConverter- The rowKeyConverter used to convert rowKey to rowData and vice versa.
-
-
Method Details
-
count
Counts the all available data for the given filters. In case of SQL, this would execute a "SELECT COUNT ... WHERE ...". In case you dont use SQL and receive bothrowCountanddatawithin a single call, this method should just return0. You must callrecalculateFirst(int, int, int)andsetRowCount(int)in yourload(int, int, java.util.Map, java.util.Map)method.- Parameters:
filterBy- a map with all filter information (only relevant for DataTable, not for eg DataView)- Returns:
- the data count
-
load
public abstract List<T> load(int first, int pageSize, Map<String, SortMeta> sortBy, Map<String, FilterMeta> filterBy) Loads the data for the given parameters.- Parameters:
first- the first entrypageSize- the page sizesortBy- a map with all sort information (only relevant for DataTable, not for eg DataView)filterBy- a map with all filter information (only relevant for DataTable, not for eg DataView)- Returns:
- the data
-
getRowData
- Specified by:
getRowDatain interfaceSelectableDataModel<T>
-
loadOne
Loads a single row for the rowIndex provided.- Parameters:
rowIndex- the row index to loadsortBy- a map with all sort informationfilterBy- a map with all filter information- Returns:
- the data
-
recalculateFirst
protected int recalculateFirst(int first, int pageSize, int rowCount) Recalculatesfirst, see #1921. Also see:UIPageableData.calculateFirst()- Parameters:
first- thefirstparam from theload(int, int, java.util.Map, java.util.Map)method.pageSize- thepageSizeparam from theload(int, int, java.util.Map, java.util.Map)method.rowCount- the newrowCount.- Returns:
- the recalculated
first.
-
getRowKey
- Specified by:
getRowKeyin interfaceSelectableDataModel<T>
-
getRowKeyFromConverter
-
getMessage
-
isRowAvailable
public boolean isRowAvailable()- Specified by:
isRowAvailablein classjavax.faces.model.DataModel<T>
-
getRowData
- Specified by:
getRowDatain classjavax.faces.model.DataModel<T>
-
getWrappedData
- Specified by:
getWrappedDatain classjavax.faces.model.DataModel<T>
-
setWrappedData
- Specified by:
setWrappedDatain classjavax.faces.model.DataModel<T>
-
getRowIndex
public int getRowIndex()- Specified by:
getRowIndexin classjavax.faces.model.DataModel<T>
-
setRowIndex
public void setRowIndex(int rowIndex) - Specified by:
setRowIndexin classjavax.faces.model.DataModel<T>
-
iterator
-
iterator
-
getRowCount
public int getRowCount()- Specified by:
getRowCountin classjavax.faces.model.DataModel<T>
-
setRowCount
public void setRowCount(int rowCount) -
getPageSize
public int getPageSize() -
setPageSize
public void setPageSize(int pageSize)
-