Using Groovy to read values from a different view object

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)[0].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.



Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips, Tricks, Events and Information around Oracle JDeveloper, ADF, and Oracle Forms

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today