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
UNKNOWN_ROW_LIMIT, UNLIMITED_ROW
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, isContainerEmpty
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
public 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 RowKeyIndex
getRowKey
in class CollectionModel
CollectionModel.setRowKey(java.lang.Object)
public void setRowKey(Object rowKey)
setRowKey
in interface RowKeyIndex
setRowKey
in class CollectionModel
rowKey
- 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 TreeModel
childKey
- the rowKey of the child row.public int getRowCount()
RowKeyIndex
getRowCount
in interface RowKeyIndex
getRowCount
in class javax.faces.model.DataModel
public Object getRowData()
RowKeyIndex
getRowData
in interface RowKeyIndex
getRowData
in class javax.faces.model.DataModel
RowKeyIndex.getRowKey()
,
RowKeyIndex.getRowIndex()
public boolean isRowAvailable()
RowKeyIndex
RowKeyIndex.getRowCount()
).isRowAvailable
in interface RowKeyIndex
isRowAvailable
in class javax.faces.model.DataModel
RowKeyIndex.getRowKey()
,
RowKeyIndex.getRowIndex()
public boolean isContainer()
TreeModel
TreeModel.isContainerEmpty()
to see if the current container element actually
has children, or is an empty container.isContainer
in class TreeModel
public void enterContainer()
TreeModel
TreeModel.isContainer()
returns true.
DataModel.getRowCount()
can be used to get the number of children.enterContainer
in class TreeModel
public void exitContainer()
TreeModel
exitContainer
in class TreeModel
public Object getWrappedData()
getWrappedData
in class javax.faces.model.DataModel
public void setWrappedData(Object data)
setWrappedData
in class javax.faces.model.DataModel
public final String getChildProperty()
public final void setChildProperty(String childProperty)
public int getRowIndex()
RowKeyIndex
getRowIndex
in interface RowKeyIndex
getRowIndex
in class javax.faces.model.DataModel
public void setRowIndex(int rowIndex)
RowKeyIndex
setRowIndex
in interface RowKeyIndex
setRowIndex
in class javax.faces.model.DataModel
rowIndex
- the zero-based index of the value to make current.
Use -1 to clear the current valuepublic boolean isSortable(String property)
CollectionModel
isSortable
in class CollectionModel
public List<SortCriterion> getSortCriteria()
CollectionModel
getSortCriteria
in class CollectionModel
SortCriterion
public void setSortCriteria(List<SortCriterion> criteria)
CollectionModel
setSortCriteria
in class CollectionModel
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.SortCriterion
protected 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()
MenuModel
The 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 MenuModel
public void setFocusRowKey(Object focusRowKey)
Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.