org.apache.myfaces.trinidad.model.ViewIdPropertyMenuModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trinidad-api Show documentation
Show all versions of trinidad-api Show documentation
Public API for the Apache MyFaces Trinidad project
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.myfaces.trinidad.model;
import java.beans.IntrospectionException;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.el.PropertyResolver;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
/**
* 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");
*
*/
// TODO - support for mutable trees?
public class ViewIdPropertyMenuModel extends BaseMenuModel
{
/**
* No-arg constructor for use with managed-beans.
* Must call the {@link #setViewIdProperty} and
* {@link #setWrappedData} methods after constructing this instance.
*/
public ViewIdPropertyMenuModel()
{
super();
_focusPathMap = new HashMap