org.richfaces.model

## Class CollectionDataModel<E>

- java.lang.Object
- - javax.faces.model.DataModel<E>
  - - org.richfaces.model.CollectionDataModel<E>

- All Implemented Interfaces:
    Iterable<E>

      public class CollectionDataModel<E>
      extends javax.faces.model.DataModel<E>

  CollectionDataModel is a convenience implementation of `DataModel` that wraps an `Collection` of Java objects.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CollectionDataModel()` Construct a new `CollectionDataModel` with no specified wrapped data.
    `CollectionDataModel(Collection<E> collection)` Construct a new `CollectionDataModel` wrapping the specified list.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getRowCount()` If there is `wrappedData` available, return the length of the list.
    `E` | `getRowData()` If row data is available, return the array element at the index specified by `rowIndex`.
    `int` | `getRowIndex()`
    `Object` | `getWrappedData()`
    `boolean` | `isRowAvailable()` Return `true` if there is `wrappedData` available, and the current value of `rowIndex` is greater than or equal to zero, and less than the size of the list.
    `void` | `setRowIndex(int rowIndex)`
    `void` | `setWrappedData(Object data)` Set the wrapped data.

    - ### Methods inherited from class javax.faces.model.DataModel

      `addDataModelListener, getDataModelListeners, iterator, removeDataModelListener`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CollectionDataModel

          public CollectionDataModel()

      Construct a new `CollectionDataModel` with no specified wrapped data.

    - #### CollectionDataModel

          public CollectionDataModel(Collection<E> collection)

      Construct a new `CollectionDataModel` wrapping the specified list.

      Parameters:
        `collection` - Collection to be wrapped.

  - ### Method Detail

    - #### isRowAvailable

          public boolean isRowAvailable()

      Return `true` if there is `wrappedData` available, and the current value of `rowIndex` is greater than or equal to zero, and less than the size of the list. Otherwise, return `false`.

      Specified by:
        `isRowAvailable` in class `javax.faces.model.DataModel<E>`
      Throws:
        `javax.faces.FacesException` - if an error occurs getting the row availability

    - #### getRowCount

          public int getRowCount()

      If there is `wrappedData` available, return the length of the list. If no `wrappedData` is available, return -1.

      Specified by:
        `getRowCount` in class `javax.faces.model.DataModel<E>`
      Throws:
        `javax.faces.FacesException` - if an error occurs getting the row count

    - #### getRowData

          public E getRowData()

      If row data is available, return the array element at the index specified by `rowIndex`. If no wrapped data is available, return `null`.

      Specified by:
        `getRowData` in class `javax.faces.model.DataModel<E>`
      Throws:
        `javax.faces.FacesException` - if an error occurs getting the row data
        `IllegalArgumentException` - if now row data is available at the currently specified row index

    - #### getRowIndex

          public int getRowIndex()

      Specified by:
        `getRowIndex` in class `javax.faces.model.DataModel<E>`
      Throws:
        `javax.faces.FacesException`

    - #### setRowIndex

          public void setRowIndex(int rowIndex)

      Specified by:
        `setRowIndex` in class `javax.faces.model.DataModel<E>`
      Throws:
        `javax.faces.FacesException`
        `IllegalArgumentException`

    - #### getWrappedData

          public Object getWrappedData()

      Specified by:
        `getWrappedData` in class `javax.faces.model.DataModel<E>`

    - #### setWrappedData

          public void setWrappedData(Object data)

      Set the wrapped data.
      Specified by:
        `setWrappedData` in class `javax.faces.model.DataModel<E>`
      Parameters:
        `data` - the wrapped data.
      Throws:
        `ClassCastException` - if `data` is non-`null` and is not a `Collection`

Copyright © 2014 JBoss by Red Hat. All rights reserved.