Top Description Inners Fields Constructors Methods
javax.faces.model

public abstract Class DataModel<E>

extends Object
implements Iterable<E>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Known Direct Subclasses
javax.faces.model.CollectionDataModel, javax.faces.model.ArrayDataModel, javax.faces.model.ScalarDataModel, javax.faces.model.ResultSetDataModel, javax.faces.model.ResultDataModel, javax.faces.model.ListDataModel, javax.faces.model.IterableDataModel
Imports
java.util.ArrayList, .Iterator, .List, .NoSuchElementException, javax.faces.component.UIData

DataModel is an abstraction around arbitrary data binding technologies that can be used to adapt a variety of data sources for use by JavaServer Faces components that support per-row processing for their child components (such as UIData.

The data collection underlying a DataModel instance is modeled as a collection of row objects that can be accessed by a zero-relative cursor (row index). The APIs provide mechanisms to position to a specified zero-relative row index, and to retrieve an object that represents the data that corresponds to the current row index.

A concrete DataModel instance is attached to a particular collection of underlying data by calling the setWrappedData() method. It can be detached from that underlying data collection by passing a null parameter to this method.

Concrete DataModel implementations must provide a public zero-arguments constructor that calls setWrappedData(null). A convenience constructor that takes a wrapped object of the appropriate type (and passes it on via a call to setWrappedData(), should also be provided.

Event listeners may be registered to receive notifications of when a new row index is selected.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final DataModelListener[]
private List<DataModelListener>
listeners

The list of registered DataModelListeners for this DataModel.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addDataModelListener(DataModelListener
The new DataModelListener to be registered
listener
)

Add a new DataModelListener to the set interested in notifications from this DataModel.

public DataModelListener[]

Returns:

the listeners for this instance, or an empty array
getDataModelListeners
()

Return the set of DataModelListeners interested in notifications from this DataModel.

public abstract int

Returns:

the number of rows of data represented by this DataModel
getRowCount
()

Return the number of rows of data objects represented by this DataModel.

public abstract E

Returns:

an object representing the data for the currently selected row index
getRowData
()

Return an object representing the data for the currently selected row index.

public abstract int

Returns:

the index of the currently selected row
getRowIndex
()

Return the zero-relative index of the currently selected row.

public abstract Object

Returns:

the Object that this model wraps.
getWrappedData
()

Return the object representing the data wrapped by this DataModel, if any.

public abstract boolean

Returns:

true if and only if there is data available at the current index, false otherwise.
isRowAvailable
()

Return a flag indicating whether there is rowData available at the current rowIndex.

public Iterator<E>
iterator()

Implements java.lang.Iterable.iterator.

Return a read-only Iterator over the row data for this model.

public void
removeDataModelListener(DataModelListener
The old DataModelListener to be deregistered
listener
)

Remove an existing DataModelListener from the set interested in notifications from this DataModel.

public abstract void
setRowIndex(int
The new zero-relative index (must be non-negative)
rowIndex
)

Set the zero-relative index of the currently selected row, or -1 to indicate that we are not positioned on a row.

public abstract void
setWrappedData(Object
Data collection to be wrapped, or null to detach from any previous data collection
data
)

Set the object representing the data collection wrapped by this DataModel.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_DATA_MODEL_LISTENERback to summary
private static final DataModelListener[] EMPTY_DATA_MODEL_LISTENER
listenersback to summary
private List<DataModelListener> listeners

The list of registered DataModelListeners for this DataModel. This variable will be null unless there is at least one registered listener.

Constructor Detail

DataModelback to summary
public DataModel()

Method Detail

addDataModelListenerback to summary
public void addDataModelListener(DataModelListener listener)

Add a new DataModelListener to the set interested in notifications from this DataModel.

Parameters
listener:DataModelListener

The new DataModelListener to be registered

Exceptions
NullPointerException:
if listener is null
getDataModelListenersback to summary
public DataModelListener[] getDataModelListeners()

Return the set of DataModelListeners interested in notifications from this DataModel. If there are no such listeners, an empty array is returned.

Returns:DataModelListener[]

the listeners for this instance, or an empty array

getRowCountback to summary
public abstract int getRowCount()

Return the number of rows of data objects represented by this DataModel. If the number of rows is unknown, or no wrappedData is available, return -1.

Returns:int

the number of rows of data represented by this DataModel

Exceptions
FacesException:
if an error occurs getting the row count
getRowDataback to summary
public abstract E getRowData()

Return an object representing the data for the currently selected row index. If no wrappedData is available, return null.

Returns:E

an object representing the data for the currently selected row index

Exceptions
FacesException:
if an error occurs getting the row data
IllegalArgumentException:
if now row data is available at the currently specified row index
getRowIndexback to summary
public abstract int getRowIndex()

Return the zero-relative index of the currently selected row. If we are not currently positioned on a row, or no wrappedData is available, return -1.

Returns:int

the index of the currently selected row

Exceptions
FacesException:
if an error occurs getting the row index
getWrappedDataback to summary
public abstract Object getWrappedData()

Return the object representing the data wrapped by this DataModel, if any.

Returns:Object

the Object that this model wraps.

isRowAvailableback to summary
public abstract boolean isRowAvailable()

Return a flag indicating whether there is rowData available at the current rowIndex. If no wrappedData is available, return false.

Returns:boolean

true if and only if there is data available at the current index, false otherwise.

Exceptions
FacesException:
if an error occurs getting the row availability
iteratorback to summary
public Iterator<E> iterator()

Implements java.lang.Iterable.iterator.

Return a read-only Iterator over the row data for this model.

Returns:Iterator<E>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
Since
2.0
removeDataModelListenerback to summary
public void removeDataModelListener(DataModelListener listener)

Remove an existing DataModelListener from the set interested in notifications from this DataModel.

Parameters
listener:DataModelListener

The old DataModelListener to be deregistered

Exceptions
NullPointerException:
if listener is null
setRowIndexback to summary
public abstract void setRowIndex(int rowIndex)

Set the zero-relative index of the currently selected row, or -1 to indicate that we are not positioned on a row. It is possible to set the row index at a value for which the underlying data collection does not contain any row data. Therefore, callers may use the isRowAvailable() method to detect whether row data will be available for use by the getRowData() method.

If there is no wrappedData available when this method is called, the specified rowIndex is stored (and may be retrieved by a subsequent call to getRowData()), but no event is sent. Otherwise, if the currently selected row index is changed by this call, a DataModelEvent will be sent to the rowSelected() method of all registered DataModelListeners.

Parameters
rowIndex:int

The new zero-relative index (must be non-negative)

Exceptions
FacesException:
if an error occurs setting the row index
IllegalArgumentException:
if rowIndex is less than -1
setWrappedDataback to summary
public abstract void setWrappedData(Object data)

Set the object representing the data collection wrapped by this DataModel. If the specified data is null, detach this DataModel from any previously wrapped data collection instead.

If data is non-null, the currently selected row index must be set to zero, and a DataModelEvent must be sent to the rowSelected() method of all registered DataModelListeners indicating that this row is now selected.

Parameters
data:Object

Data collection to be wrapped, or null to detach from any previous data collection

Exceptions
ClassCastException:
if data is not of the appropriate type for this DataModel implementation
javax.faces.model back to summary

private final Class DataModel.DataModelIterator<T>

extends Object
implements Iterator<T>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Annotations
@SuppressWarnings:unchecked

Field Summary

Modifier and TypeField and Description
private int
private DataModel<T>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public T
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Unsupported.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
private int index
modelback to summary
private DataModel<T> model

Constructor Detail

DataModelIteratorback to summary
pack-priv DataModelIterator(DataModel<T> model)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
See Also
java.util.Iterator#hasNext()
nextback to summary
public T next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:T

the next element in the iteration

Annotations
@Override
See Also
java.util.Iterator#next()
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Unsupported.

Annotations
@Override
See Also
java.util.Iterator#remove()