Class DataModel<E>
- All Implemented Interfaces:
Iterable<E>
- Direct Known Subclasses:
ArrayDataModel,CollectionDataModel,IterableDataModel,ListDataModel,ResultSetDataModel,ScalarDataModel
Note that DataModel and its standard subclasses are not serializable, as there is no state in a DataModel object itself that needs to be preserved between render and restore-view. UIData components therefore do not store their DataModel when serialized; they just evaluate their "value" EL expression to refetch the object during the apply-request-values phase.
Because DataModel is not serializable, any managed bean that needs to be serialized and which has a member of type DataModel should therefore mark that member transient. If there is a need to preserve the datalist contained within the DataModel then ensure a reference to that list is stored in a non-transient member, or use a custom serialization method that explicitly serializes dataModel.getWrappedData. See Javadoc of Faces Specification for more.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataModelListener(DataModelListener listener) abstract intReturn the number of rows of data available.abstract EReturn the object associated with the current row index.abstract intGet the current row index.abstract ObjectGet the entire collection of data associated with this component.abstract booleanReturns true if a call to getRowData will return a valid object.iterator()voidremoveDataModelListener(DataModelListener listener) abstract voidsetRowIndex(int rowIndex) Set the current row index.abstract voidsetWrappedData(Object data) Set the entire list of data associated with this component.Methods 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
-
Constructor Details
-
DataModel
public DataModel()
-
-
Method Details
-
addDataModelListener
-
getDataModelListeners
-
getRowCount
public abstract int getRowCount()Return the number of rows of data available.
If the number of rows of data available is not known then -1 is returned. This may happen for DataModels that wrap sources of data such as java.sql.ResultSet that provide an iterator to access the "next item" rather than a fixed-size collection of data.
- Returns:
- the number of rows available.
-
getRowData
Return the object associated with the current row index.Method isRowAvailable may be called before attempting to access this method, to ensure that the data is available.
- Returns:
- The object associated with the current row index.
- Throws:
RuntimeException- subclass of some kind if the current row index is not within the range of the current wrappedData property.
-
getRowIndex
public abstract int getRowIndex()Get the current row index.- Returns:
- The current row index.
-
getWrappedData
Get the entire collection of data associated with this component. Note that the actual type of the returned object depends upon the concrete subclass of DataModel; the object will represent an "ordered sequence of components", but may be implemented as an array, java.util.List, java.sql.ResultSet or other similar types.- Returns:
- the wrapped object.
-
isRowAvailable
public abstract boolean isRowAvailable()Returns true if a call to getRowData will return a valid object.- Returns:
- true if a call to getRowData will return a valid object. false otherwise.
-
iterator
-
removeDataModelListener
-
setRowIndex
public abstract void setRowIndex(int rowIndex) Set the current row index. This affects the behaviour of the getRowData method in particular.- Parameters:
rowIndex- The row index. It may be -1 to indicate "no row", or may be a value between 0 and getRowCount()-1.
-
setWrappedData
Set the entire list of data associated with this component. Note that the actual type of the provided object must match the expectations of the concrete subclass of DataModel. See getWrappedData.- Parameters:
data- The object to be wrapped.
-