Package org.primefaces.model
Class LazyDataModel<T>
- java.lang.Object
-
- javax.faces.model.DataModel<E>
-
- javax.faces.model.ListDataModel<T>
-
- org.primefaces.model.LazyDataModel<T>
-
- Type Parameters:
T
- The model class.
- All Implemented Interfaces:
Serializable
,Iterable<T>
,SelectableDataModel<T>
- Direct Known Subclasses:
JpaLazyDataModel
public abstract class LazyDataModel<T> extends javax.faces.model.ListDataModel<T> implements SelectableDataModel<T>, Serializable
DataModel to deal with huge datasets with by lazy loading, page by page.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LazyDataModel()
For serialization onlyLazyDataModel(javax.faces.convert.Converter converter)
This constructor allows to skip the implementation ofgetRowData(java.lang.String)
andgetRowKey(java.lang.Object)
, when selection is used.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
count(Map<String,FilterMeta> filterBy)
Counts the all available data for the given filters.javax.faces.convert.Converter
getConverter()
protected String
getMessage(String msg)
int
getPageSize()
int
getRowCount()
T
getRowData()
T
getRowData(String rowKey)
int
getRowIndex()
String
getRowKey(T object)
List<T>
getWrappedData()
boolean
isRowAvailable()
Iterator<T>
iterator()
Iterator<T>
iterator(Map<String,SortMeta> sortBy, Map<String,FilterMeta> filterBy)
abstract List<T>
load(int first, int pageSize, Map<String,SortMeta> sortBy, Map<String,FilterMeta> filterBy)
Loads the data for the given parameters.protected int
recalculateFirst(int first, int pageSize, int rowCount)
Recalculatesfirst
, see #1921.void
setConverter(javax.faces.convert.Converter converter)
void
setPageSize(int pageSize)
void
setRowCount(int rowCount)
void
setRowIndex(int rowIndex)
void
setWrappedData(Object list)
-
Methods inherited from class javax.faces.model.DataModel
addDataModelListener, getDataModelListeners, removeDataModelListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
LazyDataModel
public LazyDataModel()
For serialization only
-
LazyDataModel
public LazyDataModel(javax.faces.convert.Converter converter)
This constructor allows to skip the implementation ofgetRowData(java.lang.String)
andgetRowKey(java.lang.Object)
, when selection is used.- Parameters:
converter
- The converter used to convert rowKey to rowData and vice versa.
-
-
Method Detail
-
count
public abstract int count(Map<String,FilterMeta> filterBy)
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 bothrowCount
anddata
within 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
public T getRowData(String rowKey)
- Specified by:
getRowData
in interfaceSelectableDataModel<T>
-
recalculateFirst
protected int recalculateFirst(int first, int pageSize, int rowCount)
Recalculatesfirst
, see #1921. Also see:UIPageableData.calculateFirst()
- Parameters:
first
- thefirst
param from theload(int, int, java.util.Map, java.util.Map)
method.pageSize
- thepageSize
param from theload(int, int, java.util.Map, java.util.Map)
method.rowCount
- the newrowCount
.- Returns:
- the recalculated
first
.
-
getRowKey
public String getRowKey(T object)
- Specified by:
getRowKey
in interfaceSelectableDataModel<T>
-
isRowAvailable
public boolean isRowAvailable()
- Overrides:
isRowAvailable
in classjavax.faces.model.ListDataModel<T>
-
getWrappedData
public List<T> getWrappedData()
- Overrides:
getWrappedData
in classjavax.faces.model.ListDataModel<T>
-
setWrappedData
public void setWrappedData(Object list)
- Overrides:
setWrappedData
in classjavax.faces.model.ListDataModel<T>
-
getRowIndex
public int getRowIndex()
- Overrides:
getRowIndex
in classjavax.faces.model.ListDataModel<T>
-
setRowIndex
public void setRowIndex(int rowIndex)
- Overrides:
setRowIndex
in classjavax.faces.model.ListDataModel<T>
-
iterator
public Iterator<T> iterator(Map<String,SortMeta> sortBy, Map<String,FilterMeta> filterBy)
-
getRowCount
public int getRowCount()
- Overrides:
getRowCount
in classjavax.faces.model.ListDataModel<T>
-
getPageSize
public int getPageSize()
-
setPageSize
public void setPageSize(int pageSize)
-
setRowCount
public void setRowCount(int rowCount)
-
getConverter
public javax.faces.convert.Converter getConverter()
-
setConverter
public void setConverter(javax.faces.convert.Converter converter)
-
-