org.apache.myfaces.trinidad.model
Class SortableModel

java.lang.Object
  extended by javax.faces.model.DataModel
      extended by org.apache.myfaces.trinidad.model.CollectionModel
          extended by org.apache.myfaces.trinidad.model.SortableModel
All Implemented Interfaces:
RowKeyIndex

public class SortableModel
extends CollectionModel

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


Constructor Summary
SortableModel()
          No arg constructor for use as a managed-bean.
SortableModel(java.lang.Object model)
          Create a new SortableModel from the given instance.
 
Method Summary
 void addDataModelListener(javax.faces.model.DataModelListener listener)
           
 javax.faces.model.DataModelListener[] getDataModelListeners()
           
 int getRowCount()
          Gets the number of values in this collection
 java.lang.Object getRowData()
          Gets the current value identified by the current index or rowKey.
 int getRowIndex()
          Gets the index of the current value.
 java.lang.Object getRowKey()
          Gets the row key of the current row
 java.util.List<SortCriterion> getSortCriteria()
          Gets the criteria that this collection is sorted by.
 java.lang.Object getWrappedData()
           
 boolean isRowAvailable()
          Checks to make sure a value exists for the current index or rowKey.
 boolean isSortable(java.lang.String property)
          Checks to see if the underlying collection is sortable by the given property.
 void removeDataModelListener(javax.faces.model.DataModelListener listener)
           
 void setRowIndex(int rowIndex)
          Sets up a value at a particular index to be the current value.
 void setRowKey(java.lang.Object key)
          Finds the row with the matching key and makes it current
 void setSortCriteria(java.util.List<SortCriterion> criteria)
          Sorts this collection by the given criteria.
 void setWrappedData(java.lang.Object data)
          Sets the underlying data being managed by this instance.
 java.lang.String toString()
           
 
Methods inherited from class org.apache.myfaces.trinidad.model.CollectionModel
getRowData, isRowAvailable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SortableModel

public SortableModel(java.lang.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 java.lang.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 java.lang.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(java.lang.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 java.lang.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(java.lang.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(java.lang.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 java.util.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(java.util.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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


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