By Grant Ronald on Aug 15, 2011
We recently posted an ADF Insider Essentials that showed how to build an LOV switcher. In this example, Frank Nimphius wrote a custom method into the PaymentTypeVOImpl which returns the string CASH or CREDIT depending on the lookup value passed in (1 or 2). This method is then called from the Orders view object via a Groovy expression.
However, there is an even quicker way without even having to create a custom method. To explain, I'm going to use the good old Employees and Jobs tables from the HR schema. Lets assume, that when you create a new employee their default role is AC_MGR (account manager) and their default salary should be the minimun salary for an accout manager. In this case, we'll actually read the minimum salary into the EmployeesVO.Salary field from the JobsVO.Min_Salary field.
1) First create default ADF BC based on Employees and Jobs
2) In the EmployeesVO add a view accessor to JobsVO (and call it JobsView). This "links up" the EmployeesVO to the JobsVO
3) Set the default EmployeesVO.JobId to AC_MGR
4) Set the default EmployeesVO.Salary to JobsView.findByKey(key(JobId),1).MinSalary
So what does this Groovy expression do? It "walks" to the JobsVO using the JobsView accessor and then calls findByKey using the JobId. This returns an array and since we know JobId is unique we can just get the first entry's MinSalary.