Get attribute Default Value from another Entity Object

I want when creating new record in entity object to get default value of attribute from another attribute in another entity object.

For example when creating new employee I should get his manager who is manager of his department.

Let's do previous example step by step in HR schema

1- Create DepartmentsEO and EmployeesEO entity objects

 1-a Right click on model project and select  New
 1-b In the new popup window choose from left pane ADF Business Component and from Items choose Entity Object

 1-c Type in Name "DepartmentsEO" and choose from Database Schema drop-down list HR and type in Schema Object "DEPARTMENTS"

1-d Click Next until reach step 4 of 6 and check "Generate Entity Object Class" and then click Finish button

Repeat steps 1-a to 1-d for EmployeesEO
After creating EmployeesEO entity object it automatically add EmpDeptFkAssoc association which associate between Employee and his department.

2- Change the required code in EmployeesEOImpl class

  open EmployeesEOImpl class and change code in setDepartmentId method to below code
   public void setDepartmentId(Integer value) {  
     setAttributeInternal(DEPARTMENTID, value);  
     if (value != null) {  
       DepartmentsEOImpl departmentsEOImpl = this.getDepartmentsEO1();  
       if (departmentsEOImpl != null) {  
       } else {  
         //user enetr invalid data in DepartmentId  
     } else {  
       //user don't enetr data in DepartmentId  

3- Create EmployeesVO view object based on EmployeesEO entity object

 3-a  Right click on Model project and choose New View Object from drop-down list

 3-b Type EmployeeVO in Name

3-c Move EmployeeEO entity object from left side of shuttle to right side

3-d Move all attributes from left side in shuttle to right side

3-e Click next until reach step 8 of 9 and check "Add to Application Module" checkbox and then click Finish button

4- Test application Module
Right click on application module and click Run from drop-down list
In ADF Business Component Tester try to enter value 10 in DepartmentId, it automatically set ManagerId by manager of department 10

You can download example from here created by Jdeveloper

Mahmoud A. El-Sayed

Popular posts from this blog

ADF : Get Current Logged User Name

OAF : Get Current Row in Table

ADF : Working with ViewCriteria