org.apache.myfaces.custom.tree2
Class UITreeData

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by org.apache.myfaces.custom.tree2.UITreeData
All Implemented Interfaces:
javax.faces.component.NamingContainer, javax.faces.component.StateHolder, Tree
Direct Known Subclasses:
AbstractHtmlTree

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

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: 940138 $ $Date: 2010-05-01 20:34:32 -0500 (Sat, 01 May 2010) $
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 class javax.faces.component.UIComponent
bindings
 
Fields inherited from interface javax.faces.component.NamingContainer
SEPARATOR_CHAR
 
Constructor Summary
UITreeData()
          Constructor
 
Method Summary
 void broadcast(javax.faces.event.FacesEvent event)
           
 void collapseAll()
          Collapse all nodes by default.
 void collapsePath(java.lang.String[] nodePath)
          Expands all of the nodes in the specfied path.
 void encodeBegin(javax.faces.context.FacesContext context)
           
 void encodeEnd(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()
           
 java.lang.Object getModel()
          Gets the model of the TreeData - due to backwards-compatibility, this can also be retrieved by getValue.
 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()
          Deprecated.  
 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.
 boolean isNodeSelected()
          Indicates whether or not the current TreeNode is selected.
 void processDecodes(javax.faces.context.FacesContext context)
           
protected  void processNodes(javax.faces.context.FacesContext context, int processAction, TreeWalker walker)
           
 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 setModel(java.lang.Object model)
          Sets the model of the TreeData - due to backwards-compatibility, this can also be set by calling setValue.
 void setNodeId(java.lang.String nodeId)
           
 void setNodeSelected(javax.faces.event.ActionEvent event)
          Implements the ActionListener interface.
 void setValue(java.lang.Object value)
          Deprecated.  
 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, findComponent, getAttributes, getChildCount, getChildren, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isRendered, isTransient, processRestoreState, processSaveState, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient
 
Methods inherited from class javax.faces.component.UIComponent
encodeAll, getContainerClientId, getValueExpression, setValueExpression
 
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()
Specified by:
getFamily in class javax.faces.component.UIComponent

saveState

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

restoreState

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

encodeEnd

public void encodeEnd(javax.faces.context.FacesContext context)
               throws java.io.IOException
Overrides:
encodeEnd in class javax.faces.component.UIComponentBase
Throws:
java.io.IOException

queueEvent

public void queueEvent(javax.faces.event.FacesEvent event)
Overrides:
queueEvent in class javax.faces.component.UIComponentBase

broadcast

public void broadcast(javax.faces.event.FacesEvent event)
               throws javax.faces.event.AbortProcessingException
Overrides:
broadcast in class javax.faces.component.UIComponentBase
Throws:
javax.faces.event.AbortProcessingException

processDecodes

public void processDecodes(javax.faces.context.FacesContext context)
Overrides:
processDecodes in class javax.faces.component.UIComponentBase

processValidators

public void processValidators(javax.faces.context.FacesContext context)
Overrides:
processValidators in class javax.faces.component.UIComponentBase

processUpdates

public void processUpdates(javax.faces.context.FacesContext context)
Overrides:
processUpdates in class javax.faces.component.UIComponentBase

getClientId

public java.lang.String getClientId(javax.faces.context.FacesContext context)
Overrides:
getClientId in class javax.faces.component.UIComponentBase

setValueBinding

public void setValueBinding(java.lang.String name,
                            javax.faces.el.ValueBinding binding)
Overrides:
setValueBinding in class javax.faces.component.UIComponentBase

encodeBegin

public void encodeBegin(javax.faces.context.FacesContext context)
                 throws java.io.IOException
Overrides:
encodeBegin in class javax.faces.component.UIComponentBase
Throws:
java.io.IOException

setValue

public void setValue(java.lang.Object value)
Deprecated. 

Sets the value of the TreeData.

Parameters:
value - The new value

getModel

public java.lang.Object getModel()
Gets the model of the TreeData - due to backwards-compatibility, this can also be retrieved by getValue.

Specified by:
getModel in interface Tree
Returns:
The value

setModel

public void setModel(java.lang.Object model)
Sets the model of the TreeData - due to backwards-compatibility, this can also be set by calling setValue.

Specified by:
setModel in interface Tree
Parameters:
model - The new model

getValue

public java.lang.Object getValue()
Deprecated. 

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.

Specified by:
setVar in interface Tree
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.

Specified by:
getVar in interface Tree
Returns:
The iterator attribute

getNode

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

Specified by:
getNode in interface Tree
Returns:
The current node

getNodeId

public java.lang.String getNodeId()
Specified by:
getNodeId in interface Tree

setNodeId

public void setNodeId(java.lang.String nodeId)
Specified by:
setNodeId in interface Tree

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.

Specified by:
getPathInformation in interface Tree
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.

Specified by:
isLastChild in interface Tree
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.

Specified by:
getDataModel in interface Tree
Returns:
TreeModel

expandAll

public void expandAll()
Epands all nodes by default.

Specified by:
expandAll in interface Tree

collapseAll

public void collapseAll()
Collapse all nodes by default.

Specified by:
collapseAll in interface Tree

expandPath

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

Specified by:
expandPath in interface Tree
Parameters:
nodePath - The path to expand.

collapsePath

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

Specified by:
collapsePath in interface Tree
Parameters:
nodePath - The path to expand.

processNodes

protected void processNodes(javax.faces.context.FacesContext context,
                            int processAction,
                            TreeWalker walker)

toggleExpanded

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

Specified by:
toggleExpanded in interface Tree

isNodeExpanded

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

Specified by:
isNodeExpanded in interface Tree
Returns:
boolean

setNodeSelected

public void setNodeSelected(javax.faces.event.ActionEvent event)
Implements the ActionListener interface. Basically, this method is used to listen for node selection events (when a user has clicked on a leaf node.)

Specified by:
setNodeSelected in interface Tree
Parameters:
event - ActionEvent

isNodeSelected

public boolean isNodeSelected()
Indicates whether or not the current TreeNode is selected.

Specified by:
isNodeSelected in interface Tree
Returns:
boolean


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.