org.omnifaces.component.tree
Class Tree

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by org.omnifaces.component.tree.TreeFamily
              extended by org.omnifaces.component.tree.Tree
All Implemented Interfaces:
java.util.EventListener, javax.faces.component.NamingContainer, javax.faces.component.PartialStateHolder, javax.faces.component.StateHolder, javax.faces.event.ComponentSystemEventListener, javax.faces.event.FacesListener, javax.faces.event.SystemEventListenerHolder

public class Tree
extends TreeFamily
implements javax.faces.component.NamingContainer

Tree is an UIComponent that supports data binding to a tree of data objects represented by a TreeModel instance, which is the current value of this component itself (typically established via a ValueExpression). During iterative processing over the nodes of tree in the tree model, the object for the current node is exposed as a request attribute under the key specified by the var attribute. The node itself is exposed as a request attribute under the key specified by the varNode attribute.

Only children of type TreeNode are allowed and processed by this component.

This component does not have a renderer since it does not render any markup by itself. This allows the developers to have full control over the markup of the tree by declaring the appropriate JSF components or HTML elements in the markup. Here is a basic usage example:

 <o:tree value="#{bean.treeModel}" var="item" varNode="node">
   <o:treeNode>
     <ul>
       <o:treeNodeItem>
         <li>
           #{node.index} #{item.someProperty}
           <o:treeInsertChildren />
         </li>
       </o:treeNodeItem>
     </ul>
   </o:treeNode>
 </o:tree>
 

Author:
Bauke Scholtz
See Also:
TreeModel, TreeNode

Field Summary
static java.lang.String COMPONENT_TYPE
          The standard component type.
 
Fields inherited from class org.omnifaces.component.tree.TreeFamily
COMPONENT_FAMILY
 
Fields inherited from class javax.faces.component.UIComponent
BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, VIEW_LOCATION_KEY
 
Fields inherited from interface javax.faces.component.NamingContainer
SEPARATOR_CHAR
 
Constructor Summary
Tree()
           
 
Method Summary
 void broadcast(javax.faces.event.FacesEvent event)
          If the given event is an instance of the specific faces event which was created during our queueEvent(FacesEvent), then extract the node from it and set it as current node and delegate the call to the wrapped faces event.
 java.lang.String getContainerClientId(javax.faces.context.FacesContext context)
          An override which appends the index of the current model node to the client ID chain, if any available.
protected  TreeModel getCurrentModelNode()
          Returns the current node of the tree model.
 java.lang.Object getValue()
          Returns the tree model.
 java.lang.String getVar()
          Returns the name of the request attribute which exposes the wrapped data of the current node of the tree model.
 java.lang.String getVarNode()
          Returns the name of the request attribute which exposes the current node of the tree model.
protected  void process(javax.faces.context.FacesContext context, javax.faces.event.PhaseId phaseId)
          Set the root node as current node and delegate the call to processTreeNode(FacesContext, PhaseId).
protected  void processTreeNode(javax.faces.context.FacesContext context, javax.faces.event.PhaseId phaseId)
          If the current model node isn't a leaf (i.e.
 void queueEvent(javax.faces.event.FacesEvent event)
          An override which wraps the given faces event in a specific faces event which remembers the current model node.
protected  void setCurrentModelNode(javax.faces.context.FacesContext context, TreeModel currentModelNode)
          Sets the current node of the tree model.
 void setValue(java.lang.Object value)
          Sets the tree model.
 void setValueExpression(java.lang.String name, javax.el.ValueExpression binding)
          An override which checks if this isn't been invoked on var or varNode attribute.
 void setVar(java.lang.String var)
          Sets the name of the request attribute which exposes the wrapped data of the current node of the tree model.
 void setVarNode(java.lang.String varNode)
          Sets the name of the request attribute which exposes the current node of the tree model.
protected  void validateHierarchy()
          Validate the component hierarchy.
 boolean visitTree(javax.faces.component.visit.VisitContext context, javax.faces.component.visit.VisitCallback callback)
          Set the root node as current node and delegate the call to visitTreeNode(VisitContext, VisitCallback).
protected  boolean visitTreeNode(javax.faces.component.visit.VisitContext context, javax.faces.component.visit.VisitCallback callback)
          If the current model node isn't a leaf (i.e.
 
Methods inherited from class org.omnifaces.component.tree.TreeFamily
encodeChildren, getFamily, getRendersChildren, processDecodes, processSuper, processUpdates, processValidators
 
Methods inherited from class javax.faces.component.UIComponentBase
addClientBehavior, addFacesListener, clearInitialState, decode, encodeBegin, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processRestoreState, processSaveState, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding
 
Methods inherited from class javax.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getResourceBundleMap, getStateHelper, getStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, setInView, subscribeToEvent, unsubscribeFromEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_TYPE

public static final java.lang.String COMPONENT_TYPE
The standard component type.

See Also:
Constant Field Values
Constructor Detail

Tree

public Tree()
Method Detail

getContainerClientId

public java.lang.String getContainerClientId(javax.faces.context.FacesContext context)
An override which appends the index of the current model node to the client ID chain, if any available.

Overrides:
getContainerClientId in class javax.faces.component.UIComponent
See Also:
TreeModel.getIndex()

setValueExpression

public void setValueExpression(java.lang.String name,
                               javax.el.ValueExpression binding)
An override which checks if this isn't been invoked on var or varNode attribute. Finally it delegates to the super method.

Overrides:
setValueExpression in class javax.faces.component.UIComponent
Throws:
java.lang.IllegalArgumentException - When this value expression is been set on var or varNode attribute.

queueEvent

public void queueEvent(javax.faces.event.FacesEvent event)
An override which wraps the given faces event in a specific faces event which remembers the current model node.

Overrides:
queueEvent in class javax.faces.component.UIComponentBase

validateHierarchy

protected void validateHierarchy()
Validate the component hierarchy.

Specified by:
validateHierarchy in class TreeFamily
Throws:
java.lang.IllegalArgumentException - When this component is nested in another Tree, or when there aren't any children of type TreeNode.

process

protected void process(javax.faces.context.FacesContext context,
                       javax.faces.event.PhaseId phaseId)
Set the root node as current node and delegate the call to processTreeNode(FacesContext, PhaseId).

Specified by:
process in class TreeFamily
Parameters:
context - The faces context to work with.
phaseId - The current phase ID.

visitTree

public boolean visitTree(javax.faces.component.visit.VisitContext context,
                         javax.faces.component.visit.VisitCallback callback)
Set the root node as current node and delegate the call to visitTreeNode(VisitContext, VisitCallback).

Overrides:
visitTree in class javax.faces.component.UIComponent
Parameters:
context - The visit context to work with.
callback - The visit callback to work with.
Returns:
The visit result.

broadcast

public void broadcast(javax.faces.event.FacesEvent event)
               throws javax.faces.event.AbortProcessingException
If the given event is an instance of the specific faces event which was created during our queueEvent(FacesEvent), then extract the node from it and set it as current node and delegate the call to the wrapped faces event.

Overrides:
broadcast in class javax.faces.component.UIComponentBase
Throws:
javax.faces.event.AbortProcessingException

processTreeNode

protected void processTreeNode(javax.faces.context.FacesContext context,
                               javax.faces.event.PhaseId phaseId)
If the current model node isn't a leaf (i.e. it has any children), then obtain the TreeNode associated with the level of the current model node. If it isn't null, then process it according to the rules of the given phase ID. This method is also called by TreeInsertChildren.process(FacesContext, PhaseId).

Parameters:
context - The faces context to work with.
phaseId - The current phase ID.
See Also:
TreeModel.isLeaf(), TreeModel.getLevel(), TreeInsertChildren

visitTreeNode

protected boolean visitTreeNode(javax.faces.component.visit.VisitContext context,
                                javax.faces.component.visit.VisitCallback callback)
If the current model node isn't a leaf (i.e. it has any children), then obtain the TreeNode associated with the level of the current model node. If it isn't null, then visit it according to the given visit context and callback. This method is also called by TreeInsertChildren.visitTree(VisitContext, VisitCallback).

Parameters:
context - The visit context to work with.
callback - The visit callback to work with.
See Also:
TreeModel.isLeaf(), TreeModel.getLevel(), TreeInsertChildren

setCurrentModelNode

protected void setCurrentModelNode(javax.faces.context.FacesContext context,
                                   TreeModel currentModelNode)
Sets the current node of the tree model. Its wrapped data will be set as request attribute associated with the var attribute, if any. The node itself will also be set as request attribute associated with the varNode attribute, if any.

Parameters:
context - The faces context to work with.
currentModelNode - The current node of the tree model.

getCurrentModelNode

protected TreeModel getCurrentModelNode()
Returns the current node of the tree model.

Returns:
The current node of the tree model.

getValue

public java.lang.Object getValue()
Returns the tree model.

Returns:
The tree model

setValue

public void setValue(java.lang.Object value)
Sets the tree model.

Parameters:
value - The tree model.

getVar

public java.lang.String getVar()
Returns the name of the request attribute which exposes the wrapped data of the current node of the tree model.

Returns:
The name of the request attribute which exposes the wrapped data of the current node of the tree model.

setVar

public void setVar(java.lang.String var)
Sets the name of the request attribute which exposes the wrapped data of the current node of the tree model.

Parameters:
var - The name of the request attribute which exposes the wrapped data of the current node of the tree model.

getVarNode

public java.lang.String getVarNode()
Returns the name of the request attribute which exposes the current node of the tree model.

Returns:
The name of the request attribute which exposes the current node of the tree model.

setVarNode

public void setVarNode(java.lang.String varNode)
Sets the name of the request attribute which exposes the current node of the tree model.

Parameters:
varNode - The name of the request attribute which exposes the current node of the tree model.