node rich:treeNode HtmlTreeNode

Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.TreeNode
component-class | org.richfaces.component.html.HtmlTreeNode
component-family | org.richfaces.TreeNode
renderer-type | org.richfaces.TreeNodeRenderer
tag-class | org.richfaces.taglib.TreeNodeTag

## Creating the Component with a Page Tag

Here is a simple example as it could be used on a page:

Example:

    ...
        <rich:tree ... faceNode="simpleNode">
            <rich:treeNode type="simpleNode">
                <!--Tree node data displaying template-->
            </rich:treeNode>
        </rich:tree>
    ...

## Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmlTreeNode;
    ...
    HtmlTreeNode myPanel = new HtmlTreeNode();
    ...

## Details of Usage

The "icon" , "iconCollapsed" , "iconExpanded" , "iconLeaf" attributes define icons for the component. Also you can define icons using facets with the same names. If the facets are defined, the corresponding attributes are ignored and facets contents are used as icons. The width of a rendered facet area is 16px.

    ...
        <rich:tree ...>
            ...
            <rich:treeNode ...>
                <f:facet name="icon">
                    <hutputText value="A"/>
                </f:facet>
                <f:facet name="iconCollapsed">
                    <hutputText value="B"/>
                </f:facet>
                <f:facet name="iconExpanded">
                    <hutputText value="C"/>
                </f:facet>
                <f:facet name="iconLeaf">
                    <hutputText value="D"/>
                </f:facet>
            </rich:treeNode>
            ...
        </rich:tree>
    ...

## Details of Usage

As it has been mentioned above, treeNode defines a template for nodes rendering in a tree. Thus, during XML document rendering (a web.xml application) as a tree, the following nodes output (passed via var="data" on a tree) happens:

Example:

    ...
        <rich:tree ... faceNode="simpleNode" ... value="#{bean.data}" var="data">
            <rich:treeNode type="simpleNode">
                <h:outputText value="context-param:"/>
                <h:inputText value="#{data.name}"/>
            </rich:treeNode>
        </rich:tree >
    ...

Nodes output

Hence, outputText outputs the "context-param" string and then the input is output for the data.name element of this node.

Different nodes for rendering could be defined depending on some conditions on the tree level. Each condition represents some rendering template. To get more information on various treeNodesAdaptorAdaptor definition for nodes, see the tree component chapter.

Switching between expanded/collapsed modes is also managed on the tree level and defined in the corresponding section.

Default nodes of the tree level as well as ones defined with the treeNodesAdaptorAdaptor component could send Ajax requests when selected with the mouse, it's managed with the "ajaxSubmitSelection" attribute (true/false).

## Built-in Drag and Drop

The main information on Drag and Drop operations is given in the corresponding paragraph of the tree component chapter. It's only necessary to mention that each node could also be a Drag element as well as a Drop container, i.e. the container and the element have all attributes, listeners and ways of behavior similar to the ones of the <rich:draggable> and <rich:dropZone> components simultaneously.

## Events Handling

Just as Drag and Drop operations it corresponds to the one described on the tree component level for a default Node.

## Look-and-Feel Customization

For skinnability implementation, the components use a style class redefinition method. Default style classes are mapped on skin parameters.

There are two ways to redefine the appearance of all <rich:treeNode> components at once:

- Redefine the corresponding skin parameters

- Add to your style sheets style classes used by a <rich:treeNode> component

## Skin Parameters Redefinition

Skin parameters for a node element

Skin parameters | CSS properties
--- | ---
panelTextColor | color
preferableDataSizeFont | font-size
preferableDataFamilyFont | font-family

Skin parameters for a selected element

Skin parameters | CSS properties
--- | ---
headerBackgroundColor | border-color
panelTextColor | color
selectControlColor | color

Skin parameters for a mouseovered element

Skin parameters | CSS properties
--- | ---
selectControlColor | color

## Definition of Custom Style Classes

On the screenshot there are classes names that define styles for component elements.

Classes names

Classes names that define a node element

Class name | Description
--- | ---
rich-tree-node | Defines styles for a tree node
rich-tree-node-handleicon | Defines styles for a tree node handleicon
rich-tree-node-children | Defines styles for all tree node subnodes
rich-tree-node-text | Defines styles for a tree node text
rich-tree-node-icon | Defines styles for a tree node icon
rich-tree-node-icon-leaf | Defines styles for a tree node icon leaf

Classes names that define states for a node element

Class name | Description
--- | ---
rich-tree-node-selected | Defines styles for a selected tree node
rich-tree-node-highlighted | Defines styles for a highlighted tree node
rich-tree-node-handleicon-collapsed | Defines styles for a collapsed tree node handleicon
rich-tree-node-handleicon-expanded | Defines styles for a expanded tree node handleicon

In order to redefine the style for all <rich:treeNode> components on a page using CSS, it's enough to create classes with the same names and define the necessary properties in them.

To change the style of particular <rich:treeNode> components define your own style classes in the corresponding <rich:treeNode> attributes.

It is also possible to change look and feel of specific <rich:treeNode> with the help of defining for them "selectedClass" and "highlightedClass" attributes by their specific classes.

## Relevant Resources Links

How to Expand/Collapse Tree Nodes from code see here.