There was a question on ADF EMG group, about LOV description texts. While it is usually recommended to create Association and join description text attribute into VO, sometimes people are looking for different approaches (for one or another reason). Today I will tell you about approach, I recently discovered - to get LOV description text through Groovy script, without joining attribute into VO. With this approach, framework executes fault-in query for description text, directly from EO. This means, instead of one join SQL statement, there will be executed smaller SQL selects for each LOV description, plus main VO. To read more about fault-in queries executed from EO, check Steve Muench blog - Difference Between View Object Select and Entity doSelect() Method.
Download developed sample application - DescriptionAttrGroovy.zip. Make sure you have Association between main Employees EO and EO with description text:
Create new transient attribute - DepartmentName, in Employees EO. Set this attribute value as Expression and provide correct Groovy script - Departments.DepartmentName. This means we will reference DepartmentName directly through Association, without joining it into VO:
Let me repeat myself - its not really recommended approach, I personally prefer to join description attribute into VO, because it allows to run single joined query.
Make sure you set expression recalculation dependency, based on DepartmentId EO attribute:
You need to set Auto Submit = true for the same DepartmentId EO attribute, this is needed to refresh transient DepartmentName attribute:
Set DepartmentName attribute dependency on DepartmentId, everything on EO level still:
This will allow to refresh DepartmentName with correct value, when DepartmentId will be changed.
Model part is implemented at this step, let's drag and drop LOV component along with description text in UI:
We render LOV and description:
Change LOV value, description is retrieved through Groovy expression and updated as well:
Check in the log, ADF BC executes additional SQL fault-in statement, to retrieve new description value:
No Java, No Magic - all works in declarative way.