org.apache.myfaces.trinidad.model

## Class ViewIdPropertyMenuModel

- java.lang.Object
- - javax.faces.model.DataModel
  - - org.apache.myfaces.trinidad.model.CollectionModel
    - - org.apache.myfaces.trinidad.model.TreeModel
      - - org.apache.myfaces.trinidad.model.MenuModel
        - - org.apache.myfaces.trinidad.model.BaseMenuModel
          - - org.apache.myfaces.trinidad.model.ViewIdPropertyMenuModel

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

      public class ViewIdPropertyMenuModel
      extends BaseMenuModel

  Creates a MenuModel from a TreeModel where nodes in the treeModel contain viewId information.

  Each node must have either a bean getter method or a Map property that returns a viewId. There are several restrictions on the data:

  - The nodes in the tree must either be all beans or all maps, but not a mix of beans and maps.
  - The viewId of a node can be null, but if set it must be unique.
  - The tree cannot be mutable.
  The getFocusPath method
  - gets the current viewId by calling FacesContext.getCurrentInstance().getViewRoot().getViewId()
  - compares the current viewId with the viewId's in the nodes of the tree
  - returns the path to the node with the current viewId or null if the current viewId can't be found

  Assuming that NavigationTree is a tree of beans with a vieId getter, an example of creating a MenuModel with this class might look like:

           CollectionModel collectionModel = ModelUtils.toCollectionModel(new NavigationTree());
           TreeModel treeModel = new ChildPropertyTreeModel(collectionModel, "children");
           MenuModel menuModel = new ViewIdPropertyMenuModel(treeModel, "viewId");

- - ### Nested Class Summary

    - ### 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
    `ViewIdPropertyMenuModel()` No-arg constructor for use with managed-beans.
    `ViewIdPropertyMenuModel(Object instance, String viewIdProperty)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addViewId(String newViewId, String aliasedViewId)` Maps the focusPath returned when the viewId is newViewId to the focusPath returned when the viewId is aliasedViewId.
    `protected String` | `getCurrentViewId()` Returns the current viewId.
    `Object` | `getFocusRowKey()` Returns the rowKey to the current viewId.
    `String` | `getViewIdProperty()` Gets the property to use to retrieve a viewId from a node in the tree
    `void` | `setViewIdProperty(String viewIdProperty)` Sets the property to use to retrieve a viewId from a node in the tree
    `void` | `setWrappedData(Object data)`

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

      `enterContainer, exitContainer, getContainerRowKey, getRowCount, getRowData, getRowIndex, getRowKey, getWrappedData, isContainer, isRowAvailable, setRowIndex, setRowKey`

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

      `areRowsLocallyAvailable, areRowsLocallyAvailable, areRowsLocallyAvailable, getAllAncestorContainerRowKeys, getContainerRowKey, getDepth, getDepth, isChildCollectionLocallyAvailable, isChildCollectionLocallyAvailable, isChildCollectionLocallyAvailable, isContainerEmpty`

    - ### 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, getSortCriteria, isRowAvailable, isRowAvailable, isRowLocallyAvailable, isRowLocallyAvailable, isSortable, removeRowKeyChangeListener, setSortCriteria`

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

      `addDataModelListener, getDataModelListeners, iterator, removeDataModelListener`

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

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

- - ### Constructor Detail

    - #### ViewIdPropertyMenuModel

          public ViewIdPropertyMenuModel()

      No-arg constructor for use with managed-beans. Must call the `setViewIdProperty(java.lang.String)` and `setWrappedData(java.lang.Object)` methods after constructing this instance.

    - #### ViewIdPropertyMenuModel

          public ViewIdPropertyMenuModel(Object instance,
                                 String viewIdProperty)
                                  throws IntrospectionException

      Parameters:
        `instance` - a treeModel. This object will be passed to `ModelUtils.toTreeModel(java.lang.Object)`
        `viewIdProperty` - the property to use to retrieve a viewId from a node in the tree
      Throws:
        `IntrospectionException`

  - ### Method Detail

    - #### setWrappedData

          public void setWrappedData(Object data)

      Overrides:
        `setWrappedData` in class `BaseMenuModel`

    - #### getFocusRowKey

          public Object getFocusRowKey()

      Returns the rowKey to the current viewId.

      The getFocusRowKey method

      - gets the current viewId by calling FacesContext.getCurrentInstance().getViewRoot().getViewId()
      - compares the current viewId with the viewId's in the nodes of the tree
      - returns the rowKey to the node with the current viewId or null if the current viewId can't be found
      Specified by:
        `getFocusRowKey` in class `MenuModel`
      Returns:
        the rowKey to the node with the current viewId or null if the current viewId can't be found

    - #### addViewId

          public void addViewId(String newViewId,
                       String aliasedViewId)

      Maps the focusPath returned when the viewId is newViewId to the focusPath returned when the viewId is aliasedViewId. This allows view id's not in the treeModel to be mapped to a focusPath.
      Parameters:
        `newViewId` - the view id to add a focus path for
        `aliasedViewId` - the view id to use to get the focusPath to use for newViewId

    - #### getViewIdProperty

          public String getViewIdProperty()

      Gets the property to use to retrieve a viewId from a node in the tree

    - #### setViewIdProperty

          public void setViewIdProperty(String viewIdProperty)

      Sets the property to use to retrieve a viewId from a node in the tree

    - #### getCurrentViewId

          protected String getCurrentViewId()

      Returns the current viewId.

      Returns:
        the current viewId or null if the current viewId can't be found

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