Nov 2, 2012

How to set default values for Entity object attributes.

In this demo I am going to set default value of  hire date of  employees to today's date

There are 3 ways to set default values:-
1.) In the overridden create() method of the Entity object  class:-
       Generate class of  EmployeesEO Entity Object.
       Add the following code to create() immediately after the call to super.create() .

2.) Declaratively using a Groovy expression:-
  • Open the Employees Entity object and go to the Attributes page. 
  • Select the attribute HireDate.
  • Select the Details tab.
  • In the Default Value section, select Expression and enter the following Groovy
    expression: adf.currentDate

3.)In the attribute getter method:-
  • Go to getHireDate() method in the class.
  • Replace the existing code in getHireDate() with the following:

               Date hireDate = (Date)getAttributeInternal(HIREDATE);
               // check for null and return today's date if needed
               return (hireDate == null) ? (Date)Date.getCurrentDate() :

No comments:

Post a Comment