org.apache.myfaces.trinidad.model

## Class XMLMenuModel

- 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.XMLMenuModel

- All Implemented Interfaces:
    LocalRowKeyIndex, RowKeyIndex, TreeLocalRowKeyIndex

      public class XMLMenuModel
      extends BaseMenuModel

  Creates a Menu Model 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:

  o The nodes in the tree must either be all beans or all maps, but not a mix of beans and maps. o The viewId of a node can be null, but if set it must be unique. o The tree cannot be mutable.

  The getFocusRowKey method

  o gets the current viewId by calling FacesContext.getCurrentInstance().getViewRoot().getViewId() o compares the current viewId with the viewId's in the viewIdFocusPathMap that was built by traversing the tree when the model was created. o returns the focus path to the node with the current viewId or null if the current viewId can't be found. o in the case where a viewId has multiple focus paths, the currently selected node is used as a key into the nodeFocusPathMap to return the correct focus path.

  The Model is created by specifying it in the faces-config.xml file as follows

         <managed-bean>
          <managed-bean-name>hr_menu</managed-bean-name>
          <managed-bean-class>
            org.apache.myfaces.trinidad.model.XMLMenuModel
          </managed-bean-class>
          <managed-bean-scope>request</managed-bean-scope>
          <managed-property>
            <property-name>source</property-name>
            <property-class>java.lang.String</property-class>
            <value>/WEB-INF/hr-menu.xml</value>
          </managed-property>
        </managed-bean>

  Objects of this class are not thread safe and should be used only in request scope.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `XMLMenuModel.MenuContentHandler`

    - ### Nested classes/interfaces inherited from interface org.apache.myfaces.trinidad.model.LocalRowKeyIndex

      `LocalRowKeyIndex.Confidence, LocalRowKeyIndex.LocalCachingStrategy`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `SHARED_MODEL_INDICATOR_KEY` This key is used to store information about the included xml menu models which are constructed during parsing.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XMLMenuModel()`

  - ### 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 Object` | `getCacheKey()`
    `protected int` | `getContentHandlerId()`
    `protected Map<Object,List<XMLMenuModel.MenuContentHandler>>` | `getContentHandlerMap()` Returns the map of content handlers which hold the state of one XML tree.
    `boolean` | `getCreateHiddenNodes()` Gets the boolean value that determines whether or not to create nodes whose rendered attribute value is false.
    `Object` | `getCustomProperty(Object node, String propName)` Gets the list of custom properties from the node and returns the value of propName.
    `Object` | `getFocusRowKey()` Returns the rowKey to the current viewId, or in the case of where the model has nodes with duplicate viewId's and one is encountered, we return the rowKey of the currently selected node.
    `Object` | `getNode(String id)` Get a the MenuNode corresponding to the key "id" from the node id hashmap.
    `String` | `getSource()` Gets the URI to the XML menu metadata.
    `InputStream` | `getStream(String uri)` getStream - Opens an InputStream to the provided URI.
    `Map<String,List<Object>>` | `getViewIdFocusPathMap()` Get the Model's viewIdFocusPathMap
    `void` | `setCreateHiddenNodes(boolean createHiddenNodes)` Sets the boolean value that determines whether or not to create nodes whose rendered attribute value is false.
    `void` | `setCurrentlyPostedNode(Object currentNode)` Sets the currently selected node and the request method.
    `void` | `setSource(String menuMetadataUri)` setSource - specifies the XML metadata and creates the XML Menu Model.
    `void` | `setWrappedData(Object data)` Makes the TreeModel part of the menu model.

    - ### 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, fireRowKeyChange, getCachingStrategy, getEstimatedRowCount, getEstimatedRowCountConfidence, getRowData, getRowData, getSortCriteria, isRowAvailable, isRowAvailable, isRowLocallyAvailable, isRowLocallyAvailable, isSortable, removeRowKeyChangeListener, setSortCriteria`

    - ### 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`

- - ### Field Detail

    - #### SHARED_MODEL_INDICATOR_KEY

          public static final String SHARED_MODEL_INDICATOR_KEY

      This key is used to store information about the included xml menu models which are constructed during parsing.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### XMLMenuModel

          public XMLMenuModel()

  - ### Method Detail

    - #### setSource

          public void setSource(String menuMetadataUri)

      setSource - specifies the XML metadata and creates the XML Menu Model.
      Parameters:
        `menuMetadataUri` - - String URI to the XML metadata.

    - #### setWrappedData

          public void setWrappedData(Object data)

      Makes the TreeModel part of the menu model. Also creates the _viewIdFocusPathMap, _nodeFocusPathMap, and idNodeMaps.
      Overrides:
        `setWrappedData` in class `BaseMenuModel`
      Parameters:
        `data` - The Tree Model instance

    - #### getFocusRowKey

          public Object getFocusRowKey()

      Returns the rowKey to the current viewId, or in the case of where the model has nodes with duplicate viewId's and one is encountered, we return the rowKey of the currently selected node.

      The getFocusRowKey method

      - gets the current viewId by calling FacesContext.getCurrentInstance().getViewRoot().getViewId()
      - compares the current viewId with the viewId's in the viewIdFocusPathMap that was built by traversing the tree when the model was created.
      - returns the focus path to the node with the current viewId or null if the current viewId can't be found.
      - in the case where a viewId has multiple focus paths, the currently selected node is used as a key into the nodeFocusPathMap to return the correct focus path.
      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.

    - #### getSource

          public String getSource()

      Gets the URI to the XML menu metadata.
      Returns:
        String URI to the XML menu metadata.

    - #### setCreateHiddenNodes

          public void setCreateHiddenNodes(boolean createHiddenNodes)

      Sets the boolean value that determines whether or not to create nodes whose rendered attribute value is false. The default value is false. This is set through a managed property of the XMLMenuModel managed bean -- typically in the faces-config.xml file for a faces application.

    - #### getCreateHiddenNodes

          public boolean getCreateHiddenNodes()

      Gets the boolean value that determines whether or not to create nodes whose rendered attribute value is false. The default value is false. This is called by the contentHandler when parsing the XML metadata for each node.
      Returns:
        the boolean value that determines whether or not to create nodes whose rendered attribute value is false.

    - #### 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.

    - #### setCurrentlyPostedNode

          public void setCurrentlyPostedNode(Object currentNode)

      Sets the currently selected node and the request method. This is called by a selected node's doAction method. This menu node must have had its "action" attribute set, thus the method is POST.
      Parameters:
        `currentNode` - The currently selected node in the menu

    - #### getNode

          public Object getNode(String id)

      Get a the MenuNode corresponding to the key "id" from the node id hashmap.
      Parameters:
        `id` - - String node id key for the hashmap entry.
      Returns:
        The Node Object that corresponds to id.

    - #### getCustomProperty

          public Object getCustomProperty(Object node,
                                 String propName)

      Gets the list of custom properties from the node and returns the value of propName. Node must be an itemNode. If it is not an itemNode, the node will not have any custom properties and null will be returned.
      Parameters:
        `node` - Object used to get its list of custom properties
        `propName` - String name of the property whose value is desired
      Returns:
        Object value of propName for Object node.

    - #### getStream

          public InputStream getStream(String uri)

      getStream - Opens an InputStream to the provided URI.
      Parameters:
        `uri` - - String uri to a data source.
      Returns:
        InputStream to the data source.

    - #### getViewIdFocusPathMap

          public Map<String,List<Object>> getViewIdFocusPathMap()

      Get the Model's viewIdFocusPathMap
      Returns:
        the Model's viewIdFocusPathMap

    - #### getContentHandlerMap

          protected Map<Object,List<XMLMenuModel.MenuContentHandler>> getContentHandlerMap()

      Returns the map of content handlers which hold the state of one XML tree.
      Parameters:
        `scopeMap` -
      Returns:

    - #### getContentHandlerId

          protected int getContentHandlerId()

    - #### getCacheKey

          protected Object getCacheKey()

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