Fusion Developer

ADF – Recursive Tree

This post will show you how to create a multi-level tree in ADF, using a single View Object.

Download the ADF Recursive Tree JDeveloper project here…

The first step is to create your business components. I will be basing this off of the HR schema, using the employees table.

1) Enter your database details:

ADF recursive Tree with Single View Object

2) Click OK.

ADF recursive Tree with Single View Object

3) Click OK and shuttle across EMPLOYEES and DEPARTMENTS.

ADF recursive Tree with Single View Object

4) Shuttle across the Entity-based View Objects.

ADF recursive Tree with Single View Object

5) Add it to your Application Module and click Finish.

ADF recursive Tree with Single View Object

6) Open up your Employees_VO, and click the “+” on View Criteria.

ADF recursive Tree with Single View Object

7) Click on Add Item, choose ManagerId as the Attribute and choose “Is Blank” for the Operator. Name the View Criteria to something useful (isManager).

ADF recursive Tree with Single View Object

8) Open up your AppModule, shuttle the View Objects already there out, and shuttle in Employees with a child object of the Employee View Object.
Tip: rename your Data Controls here to make it easier to identify later. I named the objects topManager and employee.

ADF recursive Tree with Single View Object

9) Choose the root Employee View Object (named topManager if you renamed), then click Edit… Shuttle across the isManager View Criteria.

ADF recursive Tree with Single View Object

10) Drag the topManager Data Control onto a page, and select Tree -> ADF Tree.. When asked for the binding details, shuttle across FirstName and Lastname. As the second level, which can be accessed by pressing the “+” button, select Employees.

ADF recursive Tree with Single View Object

11) The bindings should look as follows:

ADF recursive Tree with Single View Object

12) If you run the page now, and expand some of the nodes, you should see the following:

ADF recursive Tree with Single View Object

This is how to build a multi-leveled tree based off a single View Object.

 

ADF Recursive Tree: Master Detail-Type form

The remainder of this tutorial will detail how to push the selected node into another Data Control, and to show detail in another component, like a form. This emulates a “master detail” type component. 

13) Create a new View Link for the connection between the Employees_VO and the Departments_VO. By default, when ADF creates the link, it creates the relationship as 0..1 to * between Employees and Departments, when it should be * to 1. This is because many employees can belong to 1 department, but 1 employee cannot belong to many departments.

To create a new View Link, right click on your model package, and choose “New View Link…”, name it appropriately (I named it EmpDepCustomFK1). Change the cardinality to many-to-one, then select DepartmentId under Employees as the Source Attribute, and select DepartmentId under Departments as the Destination Attribute. Then click Add.

14 - custom_vl

14) Open your Application Model, and send across an instance of the Employees_VO and an instance of Departments_VO as a child, using the custom View Link that we just created.

16 - am_custom_link

15) Click on the “Bindings” tab of the page that the tree was placed on. Click the “+” in the Executables block, and select “iterator”.

13 - bindings_iter

16) Choose the newly added Employees Data Control.

15 - employees_iterator

17) Drag the Departments1 Data Control onto the page as a form.

17 - department_on_page

18) Go to the Bindings tab again, and edit the topManager binding to edit the tree bindings. Expand the Target Data Source section, and click EL Picker. In the window that pops up, expand “ADF Bindings” -> bindings and choose the newly created iterator. Click OK.

18 - link_departments_to_tree

19) Click on the form, and click the drop-down arrow for “PartialTriggers”, then click edit. Find your tree component, and shuttle it across. This will refresh the form whenever a new node is selected. Click OK.

19 - add_partial_trigger

20) Run your new app!

You now have a recursive Tree with a form that updates whenever you click, using only bindings!

Until next time,
Kevin

 Download the ADF Recursive Tree JDeveloper project here…

5 ResponsesLeave one →

  1. Excellent post! Very helpful.

    I’m sure there is an endless number of uses for this sort of thing!

    Reply
  2. Alan Vo

     /  13 March 2014

    I truly thank you for your great article.
    Please help me this scenario:
    I want use Single Department View recursive as EmployeeVO. For example: Audit Department is Child Node of Accounting Department. Information of both that Departments is storaged at the same in DEPARTMENT table in Database and Department table references itsself in ViewLink by Dept_ID field and Dept_Parent_ID field. Then Audit Department has many Employees and these Employees will child nodes of Audit Department in the Tree. The Tree is: Parent Department –> Child Departments –> Employees of that Child Department.
    Thank you very much.
    Best Regards

    Reply
    • Alan Vo

       /  13 March 2014

      Alan Vo: I truly thank you for your great article.
      Please help me this scenario:
      I want use Single Department View recursive as your article about EmployeeVO but Department View is recursived not EmployeeVO. For example: Audit Department is Child Node of Accounting Department Node. Information of both that Departments is storaged at the same in DEPARTMENT table in Database and Department table references itsself in ViewLink by Dept_ID field and Dept_Parent_ID field. Then Audit Department has many Employees and these Employees will be child nodes of Audit Department node in the Tree. The Employee View link to Department View by Dept_ID field. The Tree is: Parent Department –> Child Departments –> Employees of that Child Department.
      Thank you very much.
      Best Regards

      Reply
      • Hi Alan,

        The best advice that I can give to help you achieve your goal with regards to the scenario you outlined above is to use a master-detail relationship between a Departments tree made in the same way that I used Employees above, and to add Employees as a child of Departments in your data model.

        Create the tree, then drag on the Employees data control as a table. Set the partialTrigger attribute of the Employees table to the ID of the tree. You can always drag on an Employees form as well, to edit the currently selected Employee.

        Please let me know if this helped!

        Reply
  3. Hi, How can I return to a view after a Task Flow Return Activity?For emaxple:”After commit, the user is redirected to another view activity…” But I can`t put a Control Flow Case from a Return to a view…I’m waiting to hear from you Andrejus.Thanks, Take Care! Regards.

    Reply

Leave a Reply

*