public class ChildPropertyMenuModel extends MenuModel
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 MenuModel by calling:
MenuModel model = new ChildPropertyMenuModel(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 MenuModel by:
MenuModel model = new ChildPropertyMenuModel(people, "kids", focusRowKey);
LocalRowKeyIndex.Confidence, LocalRowKeyIndex.LocalCachingStrategy| Constructor and Description |
|---|
ChildPropertyMenuModel()
No-arg constructor for use with managed-beans.
|
ChildPropertyMenuModel(Object instance,
String childProperty,
Object focusRowKey)
Creates a MenuModel
|
| Modifier and Type | Method and Description |
|---|---|
protected CollectionModel |
createChildModel(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 Object |
getChildData(Object parentData)
Gets the child data for a node.
|
String |
getChildProperty()
Gets the property name used to fetch the children.
|
Object |
getContainerRowKey(Object childKey)
Gets the rowKey of a given child row's container row.
|
Object |
getFocusRowKey()
Gets the focus rowKey for the current viewId.
|
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 rowKey of the current row.
|
List<SortCriterion> |
getSortCriteria()
Gets the criteria that this collection is sorted by.
|
Object |
getWrappedData()
Gets the instance being wrapped by this MenuModel.
|
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(String property)
Return true if this collection is sortable by the given property.
|
void |
setChildProperty(String childProperty)
Sets the property name used to fetch the children.
|
void |
setFocusRowKey(Object focusRowKey) |
void |
setRowIndex(int rowIndex)
Sets up a value at a particular index to be the current value.
|
void |
setRowKey(Object rowKey)
Selects a new current row.
|
void |
setSortCriteria(List<SortCriterion> criteria)
Sorts this collection by the given criteria.
|
void |
setWrappedData(Object data)
Sets the instance being wrapped by this MenuModel.
|
areRowsLocallyAvailable, areRowsLocallyAvailable, areRowsLocallyAvailable, getAllAncestorContainerRowKeys, getContainerRowKey, getDepth, getDepth, isChildCollectionLocallyAvailable, isChildCollectionLocallyAvailable, isChildCollectionLocallyAvailable, isContainerEmptyaddRowKeyChangeListener, areRowsAvailable, areRowsAvailable, areRowsAvailable, areRowsLocallyAvailable, areRowsLocallyAvailable, areRowsLocallyAvailable, clearCachedRow, clearCachedRow, clearCachedRows, clearCachedRows, clearLocalCache, ensureRowsAvailable, fireRowKeyChange, getCachingStrategy, getEstimatedRowCount, getEstimatedRowCountConfidence, getRowData, getRowData, isRowAvailable, isRowAvailable, isRowLocallyAvailable, isRowLocallyAvailable, removeRowKeyChangeListenerpublic ChildPropertyMenuModel(Object instance, String childProperty, Object focusRowKey)
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.focusRowKey - null or the row key in focuspublic ChildPropertyMenuModel()
setChildProperty(java.lang.String) and
setWrappedData(java.lang.Object) methods after constructing this instance.public Object getRowKey()
getRowKey in interface RowKeyIndexgetRowKey in class CollectionModelCollectionModel.setRowKey(java.lang.Object)public void setRowKey(Object rowKey)
setRowKey in interface RowKeyIndexsetRowKey in class CollectionModelrowKey - use null to access the root collectionpublic Object getContainerRowKey(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()
RowKeyIndexgetRowCount in interface RowKeyIndexgetRowCount in class javax.faces.model.DataModelpublic Object getRowData()
RowKeyIndexgetRowData 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()
TreeModelexitContainer in class TreeModelpublic Object getWrappedData()
getWrappedData in class javax.faces.model.DataModelpublic void setWrappedData(Object data)
setWrappedData in class javax.faces.model.DataModelpublic final String getChildProperty()
public final void setChildProperty(String childProperty)
public int getRowIndex()
RowKeyIndexgetRowIndex in interface RowKeyIndexgetRowIndex in class javax.faces.model.DataModelpublic void setRowIndex(int rowIndex)
RowKeyIndexsetRowIndex 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(String property)
CollectionModelisSortable in class CollectionModelpublic List<SortCriterion> getSortCriteria()
CollectionModelgetSortCriteria in class CollectionModelSortCriterionpublic void setSortCriteria(List<SortCriterion> criteria)
CollectionModelsetSortCriteria 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 Object getChildData(Object parentData)
createChildModel(java.lang.Object).parentData - the node to get the child data fromprotected CollectionModel createChildModel(Object childData)
ModelUtils.toCollectionModel(java.lang.Object)childData - the data to convert. This can be a List or array.public Object getFocusRowKey()
MenuModelThe value returned from calling CollectionModel.getRowKey() should remain the
same before and after calling getFocusRowKey().
Meaning initialPath and currPath should
always be equal in the following example
Object initialPath = model.getRowKey();
Object focusPath = model.getFocusRowKey();
Object currPath = model.getRowKey();
getFocusRowKey in class MenuModelpublic void setFocusRowKey(Object focusRowKey)
Copyright © 2001-2016 The Apache Software Foundation. All Rights Reserved.