Its a frequent requirement to default the first value of LOV when a new record is created.

Heres how to make it happen: DOWNLOAD

In the following example when a new department is created the first location is defaulted. User can then change location. This example can be extended to default only in certain conditions.

DepartmentEO:
Now since all business logic is in EO the logic needs to be written in EO. 
The VO that we would create for LOV on locationId attribute is added as accessor in DepartmentsEO.

On LocationId add the groovy expression as follows.


The main logic is in the defaultLocationId() where we use the accessor VO to get the first record and set its locationId
   public Number defaultLocationId() {

      Number locId = (Number)getAttributeInternal(LOCATIONID);
      if (locId == null) {
         LocationsVORowImpl locRow = (LocationsVORowImpl)getLocationsVO1().first();
         if (locRow != null) {
            locId = locRow.getLocationId();
         }
      }
      return locId;
   }

DepartmentsVO:
Create a LOV on locationId attribute. Notice that the view accessor on EO is visible in VO and can be used on LOV.
 

Page:
Create a new page with a form based on DepartmentsVO. Also drop CreateNew, Commit and Rollback actions as buttons.


Thats it the groovy expression will do the trick.

Newer Posts Older Posts Home