|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.faces.model.DataModel
org.apache.myfaces.trinidad.model.CollectionModel
org.apache.myfaces.trinidad.model.TreeModel
org.apache.myfaces.trinidad.model.ChildPropertyTreeModel
public class ChildPropertyTreeModel
Creates a TreeModel from a List of beans. To use this class you must have a tree of beans (or Maps). The structure of your tree must be a List (or array) of root beans, and each bean must have a getter method (or Map property) that returns the children List. All elements of your tree must be the same type.
Suppose you have a bean called EmpBean that contains the data for a particular employee. Suppose this bean has a method called getDirectReports() that returns a List of EmpBeans which are the direct reports of the employee. Suppose there is a List called "founders" which is the root list of EmpBeans. Now you can construct a TreeModel by calling
TreeModel model = new ChildPropertyTreeModel(founders, "directReports");Bean rules will be used to find an appropriate getter method for the "directReports" property. java.util.Maps are also supported instead of beans.
Example: Given the following class:
public class Person
{
public Person(String name)
{
_name = name;
}
public String getName()
{
return _name;
}
public List getKids()
{
return _kids;
}
private final String _name;
private final List _kids = new ArrayList();
}
You can construct a tree by:
Person john = new Person("John Smith");
Person kim = new Person("Kim Smith");
Person tom = new Person("Tom Smith");
Person ira = new Person("Ira Wickrememsinghe");
Person mallika = new Person("Mallika Wickremesinghe");
john.getKids().add(kim);
john.getKids().add(tom);
ira.getKids().add(mallika);
// create the list of root nodes:
List people = new ArrayList();
people.add(john);
people.add(ira);
Now you can construct a TreeModel by:
TreeModel model = new ChildPropertyTreeModel(people, "kids");
| Constructor Summary | |
|---|---|
ChildPropertyTreeModel()
No-arg constructor for use with managed-beans. |
|
ChildPropertyTreeModel(java.lang.Object instance,
java.lang.String childProperty)
Creates a TreeModel |
|
| Method Summary | |
|---|---|
protected CollectionModel |
createChildModel(java.lang.Object childData)
Converts childData into a CollectionModel. |
void |
enterContainer()
This Collection changes to reflect the children of the current rowData, and the current rowData changes to be null. |
void |
exitContainer()
Pops back up to the parent collection. |
protected java.lang.Object |
getChildData(java.lang.Object parentData)
Gets the child data for a node. |
java.lang.String |
getChildProperty()
Gets the property name used to fetch the children. |
java.lang.Object |
getContainerRowKey(java.lang.Object childKey)
Gets the rowKey of a given child row's container row. |
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 rowKey of the current row. |
java.util.List<SortCriterion> |
getSortCriteria()
Gets the criteria that this collection is sorted by. |
java.lang.Object |
getWrappedData()
Gets the instance being wrapped by this TreeModel. |
boolean |
isContainer()
Tests to see if the row identified by getRowData() is a container element. |
boolean |
isRowAvailable()
Checks to make sure a value exists for the current index or rowKey. |
boolean |
isSortable(java.lang.String property)
Return true if this collection is sortable by the given property. |
void |
setChildProperty(java.lang.String childProperty)
Sets the property name used to fetch the children. |
void |
setRowIndex(int rowIndex)
Sets up a value at a particular index to be the current value. |
void |
setRowKey(java.lang.Object rowKey)
Selects a new current row. |
void |
setSortCriteria(java.util.List<SortCriterion> criteria)
Sorts this collection by the given criteria. |
void |
setWrappedData(java.lang.Object data)
Sets the instance being wrapped by this TreeModel. |
| Methods inherited from class org.apache.myfaces.trinidad.model.TreeModel |
|---|
getAllAncestorContainerRowKeys, getContainerRowKey, getDepth, getDepth, isContainerEmpty |
| Methods inherited from class org.apache.myfaces.trinidad.model.CollectionModel |
|---|
getRowData, isRowAvailable |
| Methods inherited from class javax.faces.model.DataModel |
|---|
addDataModelListener, getDataModelListeners, removeDataModelListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ChildPropertyTreeModel(java.lang.Object instance,
java.lang.String childProperty)
instance - The Collection of root nodes of this tree.
This can be a List or array of beans (or Maps).
This instance is first converted into a CollectionModel (see
ModelUtils.toCollectionModel(java.lang.Object)).childProperty - This property will be used to get at the child Lists
from each bean (or Map). Bean rules will be used to find a getter method
that matches this property. If each node is a Map, this property will be
passed in to the Map's get method to get the child List.public ChildPropertyTreeModel()
setChildProperty(java.lang.String) and
setWrappedData(java.lang.Object) methods after constructing this instance.
| Method Detail |
|---|
public java.lang.Object getRowKey()
getRowKey in interface RowKeyIndexgetRowKey in class CollectionModelCollectionModel.setRowKey(java.lang.Object)public void setRowKey(java.lang.Object rowKey)
setRowKey in interface RowKeyIndexsetRowKey in class CollectionModelrowKey - use null to access the root collectionpublic java.lang.Object getContainerRowKey(java.lang.Object childKey)
TreeModel|-Root1 (rowKey="r1", containerRowKey=null) | |-Folder1 (rowKey="r1f1", containerRowKey="r1") | | |-Node1 (rowKey="r1f1n1", containerRowKey="r1f1") | | |-Node2 (rowKey="r1f1n2", containerRowKey="r1f1")
getContainerRowKey in class TreeModelchildKey - the rowKey of the child row.
public int getRowCount()
RowKeyIndex
getRowCount in interface RowKeyIndexgetRowCount in class javax.faces.model.DataModelpublic java.lang.Object getRowData()
RowKeyIndex
getRowData in interface RowKeyIndexgetRowData in class javax.faces.model.DataModelRowKeyIndex.getRowKey(),
RowKeyIndex.getRowIndex()public boolean isRowAvailable()
RowKeyIndexRowKeyIndex.getRowCount()).
isRowAvailable in interface RowKeyIndexisRowAvailable in class javax.faces.model.DataModelRowKeyIndex.getRowKey(),
RowKeyIndex.getRowIndex()public boolean isContainer()
TreeModelTreeModel.isContainerEmpty() to see if the current container element actually
has children, or is an empty container.
isContainer in class TreeModelpublic void enterContainer()
TreeModelTreeModel.isContainer() returns true.
DataModel.getRowCount() can be used to get the number of children.
enterContainer in class TreeModelpublic void exitContainer()
TreeModel
exitContainer in class TreeModelpublic java.lang.Object getWrappedData()
getWrappedData in class javax.faces.model.DataModelpublic void setWrappedData(java.lang.Object data)
setWrappedData in class javax.faces.model.DataModelpublic final java.lang.String getChildProperty()
public final void setChildProperty(java.lang.String childProperty)
public int getRowIndex()
RowKeyIndex
getRowIndex in interface RowKeyIndexgetRowIndex in class javax.faces.model.DataModelpublic void setRowIndex(int rowIndex)
RowKeyIndex
setRowIndex in interface RowKeyIndexsetRowIndex in class javax.faces.model.DataModelrowIndex - the zero-based index of the value to make current.
Use -1 to clear the current valuepublic boolean isSortable(java.lang.String property)
CollectionModel
isSortable in class CollectionModelpublic java.util.List<SortCriterion> getSortCriteria()
CollectionModel
getSortCriteria in class CollectionModelSortCriterionpublic void setSortCriteria(java.util.List<SortCriterion> criteria)
CollectionModel
setSortCriteria in class CollectionModelcriteria - 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.SortCriterionprotected java.lang.Object getChildData(java.lang.Object parentData)
createChildModel(java.lang.Object).
parentData - the node to get the child data from
protected CollectionModel createChildModel(java.lang.Object childData)
ModelUtils.toCollectionModel(java.lang.Object)
childData - the data to convert. This can be a List or array.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||