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.
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!