org.apache.myfaces.custom.tree2
Class UITreeData

java.lang.Object
  extended byjavax.faces.component.UIComponent
      extended byjavax.faces.component.UIComponentBase
          extended byorg.apache.myfaces.custom.tree2.UITreeData
All Implemented Interfaces:
javax.faces.component.NamingContainer, javax.faces.component.StateHolder
Direct Known Subclasses:
HtmlTree

public class UITreeData
extends javax.faces.component.UIComponentBase
implements javax.faces.component.NamingContainer

TreeData is a UIComponent that supports binding data stored in a tree represented by a TreeNode instance. During iterative processing over the tree nodes in the data model, the object for the current node is exposed as a request attribute under the key specified by the var property. Renderers of this component should use the appropriate facet to assist in rendering.

Version:
$Revision: 291921 $ $Date: 2005-09-27 08:08:36 -0400 (Tue, 27 Sep 2005) $
Author:
Sean Schofield, Hans Bergsten (Some code taken from an example in his O'Reilly JavaServer Faces book. Copied with permission)

Field Summary
static java.lang.String COMPONENT_FAMILY
           
static java.lang.String COMPONENT_TYPE
           
 
Fields inherited from interface javax.faces.component.NamingContainer
SEPARATOR_CHAR
 
Constructor Summary
UITreeData()
          Constructor
 
Method Summary
 void broadcast(javax.faces.event.FacesEvent event)
           
 void collapsePath(java.lang.String[] nodePath)
          Expands all of the nodes in the specfied path.
 void encodeBegin(javax.faces.context.FacesContext context)
           
 void expandAll()
          Epands all nodes by default.
 void expandPath(java.lang.String[] nodePath)
          Expands all of the nodes in the specfied path.
 java.lang.String getClientId(javax.faces.context.FacesContext context)
           
 TreeModel getDataModel()
          Returns a previously cached TreeModel, if any, or sets the cache variable to either the current value (if its a TreeModel) or to a new instance of TreeModel (if it's a TreeNode) with the provided value object as the root node.
 java.lang.String getFamily()
           
 TreeNode getNode()
          Calls through to the TreeModel and returns the current TreeNode or null.
 java.lang.String getNodeId()
           
 java.lang.String[] getPathInformation(java.lang.String nodeId)
          Gets an array of String containing the ID's of all of the TreeNodes in the path to the specified node.
 java.lang.Object getValue()
          Gets the value of the TreeData.
 java.lang.String getVar()
          Return the request-scope attribute under which the data object for the current node will be exposed when iterating.
 boolean isLastChild(java.lang.String nodeId)
          Indicates whether or not the specified TreeNode is the last child in the List of children.
 boolean isNodeExpanded()
          Indicates whether or not the current TreeNode is expanded.
protected  void processChildNodes(javax.faces.context.FacesContext context, TreeNode parentNode, int processAction)
          Process the child nodes of the supplied parent TreeNode.
 void processDecodes(javax.faces.context.FacesContext context)
           
 void processUpdates(javax.faces.context.FacesContext context)
           
 void processValidators(javax.faces.context.FacesContext context)
           
 void queueEvent(javax.faces.event.FacesEvent event)
           
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object state)
           
 java.lang.Object saveState(javax.faces.context.FacesContext context)
           
 void setNodeId(java.lang.String nodeId)
           
 void setValue(java.lang.Object value)
          Sets the value of the TreeData.
 void setValueBinding(java.lang.String name, javax.faces.el.ValueBinding binding)
           
 void setVar(java.lang.String var)
          Set the request-scope attribute under which the data object for the current node wil be exposed when iterating.
 void toggleExpanded()
          Toggle the expanded state of the current node.
 
Methods inherited from class javax.faces.component.UIComponentBase
addFacesListener, decode, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getFacesContext, getFacesListeners, getFacet, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, isRendered, isTransient, processRestoreState, processSaveState, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient
 
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
See Also:
Constant Field Values

COMPONENT_FAMILY

public static final java.lang.String COMPONENT_FAMILY
See Also:
Constant Field Values
Constructor Detail

UITreeData

public UITreeData()
Constructor

Method Detail

getFamily

public java.lang.String getFamily()

saveState

public java.lang.Object saveState(javax.faces.context.FacesContext context)
Specified by:
saveState in interface javax.faces.component.StateHolder

restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         java.lang.Object state)
Specified by:
restoreState in interface javax.faces.component.StateHolder

queueEvent

public void queueEvent(javax.faces.event.FacesEvent event)

broadcast

public void broadcast(javax.faces.event.FacesEvent event)
               throws javax.faces.event.AbortProcessingException
Throws:
javax.faces.event.AbortProcessingException

processDecodes

public void processDecodes(javax.faces.context.FacesContext context)

processValidators

public void processValidators(javax.faces.context.FacesContext context)

processUpdates

public void processUpdates(javax.faces.context.FacesContext context)

getClientId

public java.lang.String getClientId(javax.faces.context.FacesContext context)

setValueBinding

public void setValueBinding(java.lang.String name,
                            javax.faces.el.ValueBinding binding)

encodeBegin

public void encodeBegin(javax.faces.context.FacesContext context)
                 throws java.io.IOException
Throws:
java.io.IOException

setValue

public void setValue(java.lang.Object value)
Sets the value of the TreeData.

Parameters:
value - The new value

getValue

public java.lang.Object getValue()
Gets the value of the TreeData.

Returns:
The value

setVar

public void setVar(java.lang.String var)
Set the request-scope attribute under which the data object for the current node wil be exposed when iterating.

Parameters:
var - The new request-scope attribute name

getVar

public java.lang.String getVar()
Return the request-scope attribute under which the data object for the current node will be exposed when iterating. This property is not enabled for value binding expressions.

Returns:
The iterrator attribute

getNode

public TreeNode getNode()
Calls through to the TreeModel and returns the current TreeNode or null.

Returns:
The current node

getNodeId

public java.lang.String getNodeId()

setNodeId

public void setNodeId(java.lang.String nodeId)

getPathInformation

public java.lang.String[] getPathInformation(java.lang.String nodeId)
Gets an array of String containing the ID's of all of the TreeNodes in the path to the specified node. The path information will be an array of String objects representing node ID's. The array will starting with the ID of the root node and end with the ID of the specified node.

Parameters:
nodeId - The id of the node for whom the path information is needed.
Returns:
String[]

isLastChild

public boolean isLastChild(java.lang.String nodeId)
Indicates whether or not the specified TreeNode is the last child in the List of children. If the node id provided corresponds to the root node, this returns true.

Parameters:
nodeId - The ID of the node to check
Returns:
boolean

getDataModel

public TreeModel getDataModel()
Returns a previously cached TreeModel, if any, or sets the cache variable to either the current value (if its a TreeModel) or to a new instance of TreeModel (if it's a TreeNode) with the provided value object as the root node.

Returns:
TreeModel

expandAll

public void expandAll()
Epands all nodes by default.


expandPath

public void expandPath(java.lang.String[] nodePath)
Expands all of the nodes in the specfied path.

Parameters:
nodePath - The path to expand.

collapsePath

public void collapsePath(java.lang.String[] nodePath)
Expands all of the nodes in the specfied path.

Parameters:
nodePath - The path to expand.

processChildNodes

protected void processChildNodes(javax.faces.context.FacesContext context,
                                 TreeNode parentNode,
                                 int processAction)
Process the child nodes of the supplied parent TreeNode. This method is protected so that it can be overriden by a subclass that may want to control how child nodes are processed.

Parameters:
context - FacesContext
parentNode - The parent node whose children are to be processed
processAction - An int representing the type of action to process

toggleExpanded

public void toggleExpanded()
Toggle the expanded state of the current node.


isNodeExpanded

public boolean isNodeExpanded()
Indicates whether or not the current TreeNode is expanded.

Returns:
boolean