This example will illustrate you that how you can create a dynamic tree component with the use of RCFaces core tag v:tree. In this example we have created a tree with the root node named "server" and then further it has one child node "IBMServer" and it also has few other child nodes for its components like memory, RAM, and SMPS.
To create this tree we have used the RCFaces core tag v:tree. It has some attributes which are described as below:
| Attribute | Description |
| id | A String that specifies the identifier for this component |
| value | String holding the current value for component |
| height | height value for component |
| width | width value for component |
| checkable | A boolean value indicating whether the component can be checked or not |
| selectionListener | executed when the node is selected |
| defaultImageURL | An url string for the default image |
| defaultExpandedImageURL | An url string pointing to the default image for an expanded node |
| hideRootExpandSign | A boolean value indicating whether the expand sign should be visible or not |
Here we need a TreeDemo.java file which is responsible for creating tree and its child nodes. Here is the code for TreeDemo.java as given below:
package com.roseindia.rcfaces.tree;
|
Compile this java file and put the class file into the /WEB-INF/classes folder and we need to do entry of this bean file into the faces-config.xml file. Given below is the few lines of code that you should mention in your faces-config.xml.
| <?xml version="1.0"?> <faces-config> <managed-bean> <description>TreeDemo</description> <managed-bean-name>treeDemo</managed-bean-name> <managed-bean-class> com.roseindia.rcfaces.tree.TreeDemo </managed-bean-class> <managed-bean-scope> request </managed-bean-scope> </managed-bean> </faces-config> |
TreeDemo.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
|
To run this example download the source code and start your Tomcat Server, deploy the project and type the following URL into your address bar:
http://localhost:8080/RCFExample/TreeDemo.jsf
Output:

After expanding the root node you will get the output as follows:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Creating Dynamic Tree component in RCFaces
Post your Comment