Tuesday, March 8, 2011

ADF Model: Getting attribute values from parent VO to child VO and vice versa using view link accessors

In this post, let us see how to access parent VO attributes from child VO and child VO attributes from parent VO using view link. To have the basic idea about view links and how to create them, you can go through my blog post 'ADF Model: Creating View Link'.

Example Use Case:
For example we have two VOs DeptVO and EmpVO and both are linked via foreign key 'DeptId' using the view link EmpVOToDeptVO. Here, this relationship depicts the parent-child relationship using the foreign key DeptId. In other words, for a given current EmpVO(child) row, I need to know the DeptName from DeptVO(parent). Similarly, for a given current DeptVO(parent) row, I need to know all the empVO(child) rows. Sample application demonstrating this example can be downloaded from here.

Implementation Steps:
1. Create EmpVO and DeptVO and generate RowImpl classes for both of these two VOs.

2. Now, create a new view link say DeptVOToEmpVO between these two VOs via foreign key DeptId.

3. In the view link definition, select options to generate accessors in both source and destination VOs. i.e., in DeptVO and EmpVO.

4. Checking the above options will generate accessor methods in EmpVORowImpl and DeptVORowImpl. The accessor's return type in each VO is based on the type of relationship between the VOs. In other words, as the relationship between Dept and Emp is 1-to-many, the accessor in DeptVORowImpl will return multiple Emp rows(i.e, the return type of the accessor will be RowIterator). And, the accessor in EmpVORowImpl will return a single row (as an employee can be in only one dept).

If you observe the source of EmpVO and DeptVO, you can also see that a tag is added in each of these VOs for the viewLinkAccessor.

5. Now, you can use these accessors to get reference EmpVO from  DeptVO and vice versa. You can also get attribute values from the same. Sample codes below:

Sample method in EmpVORowImpl to get the dept name.

Sample method in DeptVORowImpl to get the list of employees in the dept.

How to call/use these view link accessor methods in AMImpl methods?
This should be now pretty straightforward. Here is the sample AMImpl method which prints emp names in each dept. The code is self-explanatory.

Here is the sample output in console on running the above AMImpl method.

That's it. Now, you got the idea how to use view link accessors to get the values of child attributes from parent and vice versa. Enjoy!

Read more: Oracle ADF - Tips and Techniques: ADF Model: Getting attribute values from parent VO to child VO and vice versa using view link accessors http://www.adftips.com/2010/12/adf-model-getting-attribute-values-from.html#ixzz1G1TBg8gt


  1. Hi! I have table in my JSPX page. I search for records and then press on one of the records with right click, see: http://my.jetscreenshot.com/2677/20120203-fas1-30kb
    I set disabled property like this of my commandMenuItem:
    {code}#{row.GenResGrupa != 'true'}{code}

    But as You can see from my picture above, the disabled property do not work. Where I am wrong with my code:
    {code} {code}

    Please correct me! If You need some other information, please let me know.

    Best regards, Debuger!

  2. Stop copying blogs dude , write one of your own if you can !

    1. Hi sudipto , I am new to ADF i wrote same code in my application ,when i run it is not getting any errors but Out put is not showing in consol.
      and i have one doubt about deptRow.getAttribute("Dname") here "Dname" is what why should we give only that argument

  3. This comment has been removed by the author.