Building your own tree in ADF does not seem that easy at first sight but in fact it is not that hard if you know what to do. On the forum at OTN you often find questions about building your own model.
In this post you will find the steps needed to build your own model. In the example i just use some static data but you can rewrite it to use whatever you want.
Attached to this post you can find the TreeExample.zip which contains the example application with a very simple tree. We will build a tree that has 2 nodes in the root and the first node has 2 children.
Our TreeModel contains objects of the type TreeItem. TreeItem is not a build in class. I call it TreeItem but you can name it whatever you want. It is a regular bean with getters and setters. In order to build a tree, the class should have a method that returns its children.
This is the TreeItem class we will be using:
As you can see, the TreeItem has 3 properties:
You are free to add more properties. Every property you add to the TreeItem you can use it in the tree itself.
Next we need to create our managed bean. This will contain the TreeModel itself.
In fact we just create the rootNode and use a default TreeModel from ADF. This is the ChildPropertyTreeModel.
We will build the tree in the constructor of the bean:
The af:tree component requires a TreeModel as value so we need to create such a property as well:
In this methode we will create the actual TreeModel based upon the root we created in the constructor. As you can see we also need to specify the name of the method that will return the children. By specifying "children" as a second parameter of the ChildPropertyTreeModel constructor, we tell the framework to call getChildren() in order to retreive the list of children.
When this is done, we need to register the bean to the faces-config.xml:
As a final step we need to add the tree to the page:
When you run the application, the tree should be there with some nodes.
Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer
Comments
Creating your own TreeModel in ADF 11g
Your article is good, if possible can you provide step by step with screen shot, it will help me.
requestion for the code
above all of the codings are working.
but while i clicking the child it has to go to the particular .jspx file
Add image icon to the node
Very nice illustrated example to create a tree with static value..Nicely written...
I have followed your approach..now I want to add images to the nodes.
For that I have added a property String icon in the java class and I am passing the location of image in the string.However I am not getting the image.Please give suggestions ...
Add Icon to Node
Hello. I have the same question as the previous post. How do you suggest adding an icon to the nodes? I added a new text property for the icon path, but no icon image is displaying. An example would be great. Thanks!
Creating your own TreeModel in ADF 11g | Yannick Ongena's
nice blog. That's exactly what I was looking for.
Creaating ADF Tree Component Programmatically using Map/TreeMap
Your Article is really good , can you please let me know how to create a ADF tree component pro grammatically using MAP/TreeMap Collection.Can you please let me know the steps how to do that / if possible attach the code snippet in this blog.Hope to hear from you soon regarding this.
This is very helpful post.
This is very helpful post. Can you please suggest what provision should be made to highlight the selected tree node.
Set child Dynamically
Hi
This is very good example. But my requirement is different. I want set a child at run time. please help me.
Simply superb !!!
Simply superb !!!
Very good article
Wonderful and very useful article...
Which trinidad.jar should be included in the classpath
I tried putting trinidad-api-1.2.9.jar but JDeveloper is throwing the errors. Can you clarify on which trinidad jar I should include in the classpath?
The tree is an ADF component.
The tree is an ADF component. Not an older trinidad one. You should create an ADF application.
Action link to another Page
Hello...
I used your code and implemented my own. Beside my rules, i need the action do link to a Task-Flow method, called celula. For that i made:
TreeItem node1Child1 = new TreeItem("Child 1","celula");
For when i click on my Child 1, the action goes for adf-config.xml. At adf-config.xml i have all my other stuff's and actions working properly.
I Dont know why the action at Child is not working, could you share knowledge?
Thanks
Adapting this but for a TreeTable Model
Could you help with the changes needed to build this but for a Treetable. In advance many thanks.
I had been trying with a lot of examples but they are just not as clear as yours.
Add new comment