org.apache.myfaces.trinidad.model

## Class SortableModel

- java.lang.Object
- - javax.faces.model.DataModel
  - - org.apache.myfaces.trinidad.model.CollectionModel
    - - org.apache.myfaces.trinidad.model.SortableModel

- All Implemented Interfaces:
    Iterable, LocalRowKeyIndex, RowKeyIndex
  Direct Known Subclasses:
    RowKeyPropertyModel

      public class SortableModel
      extends CollectionModel

  Creates a CollectionModel that is sortable. All properties that implement java.lang.Comparable are deemed sortable.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `SortableModel.Decomposition` This class provides an enumeration to work with the integer values of the `Collator` decomposition values.
    `static class` | `SortableModel.Strength` This class provides an enumeration to work with the integer values of the `Collator` strength values.

    - ### Nested classes/interfaces inherited from interface org.apache.myfaces.trinidad.model.LocalRowKeyIndex

      `LocalRowKeyIndex.Confidence, LocalRowKeyIndex.LocalCachingStrategy`

  - ### Field Summary

    - ### Fields inherited from class org.apache.myfaces.trinidad.model.CollectionModel

      `UNKNOWN_ROW_LIMIT, UNLIMITED_ROW`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SortableModel()` No arg constructor for use as a managed-bean.
    `SortableModel(Object model)` Create a new SortableModel from the given instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDataModelListener(javax.faces.model.DataModelListener listener)`
    `Comparator` | `getComparator(String propertyName)` Get the comparator associated with the given property.
    `javax.faces.model.DataModelListener[]` | `getDataModelListeners()`
    `int` | `getRowCount()` Gets the number of values in this collection
    `Object` | `getRowData()` Gets the current value identified by the current index or rowKey.
    `int` | `getRowIndex()` Gets the index of the current value.
    `Object` | `getRowKey()` Gets the row key of the current row
    `List<SortCriterion>` | `getSortCriteria()` Gets the criteria that this collection is sorted by.
    `Object` | `getWrappedData()`
    `boolean` | `isRowAvailable()` Checks to make sure a value exists for the current index or rowKey.
    `boolean` | `isSortable(String property)` Checks to see if the underlying collection is sortable by the given property.
    `void` | `removeDataModelListener(javax.faces.model.DataModelListener listener)`
    `void` | `setCollator(String propertyName, SortableModel.Strength collatorStrength, SortableModel.Decomposition collatorDecomposition)` Convenience method to set a compatator for a property using a `Collator` setup with the given strength and decomposition values.
    `void` | `setComparator(String propertyName, Comparator comparator)` Set a custom comparator to use to sort the given property name.
    `void` | `setRowIndex(int rowIndex)` Sets up a value at a particular index to be the current value.
    `void` | `setRowKey(Object key)` Finds the row with the matching key and makes it current
    `void` | `setSortCriteria(List<SortCriterion> criteria)` Sorts this collection by the given criteria.
    `void` | `setWrappedData(Object data)` Sets the underlying data being managed by this instance.
    `String` | `toString()`

    - ### Methods inherited from class org.apache.myfaces.trinidad.model.CollectionModel

      `addRowKeyChangeListener, areRowsAvailable, areRowsAvailable, areRowsAvailable, areRowsLocallyAvailable, areRowsLocallyAvailable, areRowsLocallyAvailable, clearCachedRow, clearCachedRow, clearCachedRows, clearCachedRows, clearLocalCache, ensureRowsAvailable, fireRowKeyChange, getCachingStrategy, getEstimatedRowCount, getEstimatedRowCountConfidence, getRowData, getRowData, getRowLimit, isRowAvailable, isRowAvailable, isRowLocallyAvailable, isRowLocallyAvailable, removeRowKeyChangeListener`

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

      `iterator`

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

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

- - ### Constructor Detail

    - #### SortableModel

          public SortableModel(Object model)

      Create a new SortableModel from the given instance.
      Parameters:
        `model` - This will be converted into a `DataModel`
      See Also:
        `setWrappedData(java.lang.Object)`

    - #### SortableModel

          public SortableModel()

      No arg constructor for use as a managed-bean. Must call setWrappedData before using this instance.

  - ### Method Detail

    - #### getRowData

          public Object getRowData()

      Description copied from interface: `RowKeyIndex`
      Gets the current value identified by the current index or rowKey.
      Specified by:
        `getRowData` in interface `RowKeyIndex`
      Specified by:
        `getRowData` in class `javax.faces.model.DataModel`
      Returns:
        null if the current value has been cleared.
      See Also:
        `RowKeyIndex.getRowKey()`, `RowKeyIndex.getRowIndex()`

    - #### getWrappedData

          public Object getWrappedData()

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

    - #### isRowAvailable

          public boolean isRowAvailable()

      Description copied from interface: `RowKeyIndex`
      Checks to make sure a value exists for the current index or rowKey. This is useful if the number of values in this collection is not known (See `RowKeyIndex.getRowCount()`).
      Specified by:
        `isRowAvailable` in interface `RowKeyIndex`
      Specified by:
        `isRowAvailable` in class `javax.faces.model.DataModel`
      Returns:
        true if a value exists; false otherwise.
      See Also:
        `RowKeyIndex.getRowKey()`, `RowKeyIndex.getRowIndex()`

    - #### setWrappedData

          public void setWrappedData(Object data)

      Sets the underlying data being managed by this instance.
      Specified by:
        `setWrappedData` in class `javax.faces.model.DataModel`
      Parameters:
        `data` - This Object will be converted into a `DataModel`.
      See Also:
        `ModelUtils.toDataModel(java.lang.Object)`

    - #### getRowCount

          public int getRowCount()

      Description copied from interface: `RowKeyIndex`
      Gets the number of values in this collection
      Specified by:
        `getRowCount` in interface `RowKeyIndex`
      Specified by:
        `getRowCount` in class `javax.faces.model.DataModel`
      Returns:
        -1 if the number of values is not known.

    - #### setRowIndex

          public void setRowIndex(int rowIndex)

      Description copied from interface: `RowKeyIndex`
      Sets up a value at a particular index to be the current value. The current value is returned by calling {link #getRowData}
      Specified by:
        `setRowIndex` in interface `RowKeyIndex`
      Specified by:
        `setRowIndex` in class `javax.faces.model.DataModel`
      Parameters:
        `rowIndex` - the zero-based index of the value to make current. Use -1 to clear the current value

    - #### getRowIndex

          public int getRowIndex()

      Description copied from interface: `RowKeyIndex`
      Gets the index of the current value. The current value is returned by calling {link #getRowData}
      Specified by:
        `getRowIndex` in interface `RowKeyIndex`
      Specified by:
        `getRowIndex` in class `javax.faces.model.DataModel`
      Returns:
        the zero-based index of the current value, or -1 if there is no current value

    - #### getRowKey

          public Object getRowKey()

      Gets the row key of the current row
      Specified by:
        `getRowKey` in interface `RowKeyIndex`
      Specified by:
        `getRowKey` in class `CollectionModel`
      Returns:
        this key should be Serializable and immutable.
      See Also:
        `CollectionModel.setRowKey(java.lang.Object)`

    - #### setRowKey

          public void setRowKey(Object key)

      Finds the row with the matching key and makes it current
      Specified by:
        `setRowKey` in interface `RowKeyIndex`
      Specified by:
        `setRowKey` in class `CollectionModel`
      Parameters:
        `key` - the rowKey, previously obtained from `CollectionModel.getRowKey()`.

    - #### addDataModelListener

          public void addDataModelListener(javax.faces.model.DataModelListener listener)

      Overrides:
        `addDataModelListener` in class `javax.faces.model.DataModel`

    - #### getDataModelListeners

          public javax.faces.model.DataModelListener[] getDataModelListeners()

      Overrides:
        `getDataModelListeners` in class `javax.faces.model.DataModel`

    - #### removeDataModelListener

          public void removeDataModelListener(javax.faces.model.DataModelListener listener)

      Overrides:
        `removeDataModelListener` in class `javax.faces.model.DataModel`

    - #### isSortable

          public boolean isSortable(String property)

      Checks to see if the underlying collection is sortable by the given property.
      Overrides:
        `isSortable` in class `CollectionModel`
      Parameters:
        `property` - The name of the property to sort the underlying collection by.
      Returns:
        true, if the property implements java.lang.Comparable

    - #### getSortCriteria

          public List<SortCriterion> getSortCriteria()

      Description copied from class: `CollectionModel`
      Gets the criteria that this collection is sorted by. This method should never return null. This implementation always returns an empty List.
      Overrides:
        `getSortCriteria` in class `CollectionModel`
      Returns:
        each element in this List is of type SortCriterion. An empty list is returned if this collection is not sorted.
      See Also:
        `SortCriterion`

    - #### setSortCriteria

          public void setSortCriteria(List<SortCriterion> criteria)

      Description copied from class: `CollectionModel`
      Sorts this collection by the given criteria.
      Overrides:
        `setSortCriteria` in class `CollectionModel`
      Parameters:
        `criteria` - Each element in this List must be of type SortCriterion. The empty list may be used to cancel any sort order. null should be treated the same as an empty list.
      See Also:
        `SortCriterion`

    - #### getComparator

          public Comparator getComparator(String propertyName)

      Get the comparator associated with the given property.
      Parameters:
        `propertyName` - the property
      Returns:
        the comparator or null if one has not been set

    - #### setComparator

          public void setComparator(String propertyName,
                           Comparator comparator)

      Set a custom comparator to use to sort the given property name.
      Parameters:
        `propertyName` - the property with which to associate the comparator
        `comparator` - the comparator to use, or null to remove one

    - #### setCollator

          public void setCollator(String propertyName,
                         SortableModel.Strength collatorStrength,
                         SortableModel.Decomposition collatorDecomposition)

      Convenience method to set a compatator for a property using a `Collator` setup with the given strength and decomposition values.
      Parameters:
        `propertyName` - the property
        `collatorStrength` - the stregth to use or null to leave as the default for the default locale
        `collatorDecomposition` - the decomposition to use or null to leave as the default for the default locale
      See Also:
        `setComparator(String, Comparator)`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.