Retrieve the Old Value of an Attribute in the View Object

Sometimes we need to access the old value of an attribute, this is explained well by Chris Muir in ADF Insider video Retrieving the previous value of an ADF BC attribute. This can be done by using getPostedAttribute method in the EntityImpl class, this method gets the value originally read value for  a specific attribute from the database and it has a protected access modifier. But what if you want to access the old value in the View object and you don’t have a control on the Entity object; such as if the entity objects are deployed as ADF library jar and you don’t have any privilege to access or modify these entities; is it possible to access the old value from the view object? in this post I will show how do this in an easy way. Suppose we want to access the old value of the department name attribute in the DepartmentsView  which is based on Departments table in HR schema.

  1.  Create a transient attribute, OldDepartmentName in the DepartmentsView.
  2. Generate the DepartmentsViewRowImpl class, check the include accessors check box, this will add getter/setter methods for all the attributes of this view object. by default the getDepartmentName method will look like this: 
    /**
    * Gets the attribute value for the calculated attribute OldDepartmentName.
    * @return the OldDepartmentName
    */
    public String getOldDepartmentName() {
    return (String) getAttributeInternal(OLDDEPARTMENTNAME);
    }
  3. Override the getOldDepartmentName() method to:
        /**
         * Gets the attribute value for the calculated attribute OldDepartmentName.
         * @return the OldDepartmentName
         */
        public String getOldDepartmentName() {
            byte status = EntityImpl.STATUS_UNMODIFIED;
            return (String) getAttributeInternal(DEPARTMENTNAME, status);
        }

Now, the getOldDepartmentName() will return the old value from the database.

Advertisements

Leave a comment

Filed under ADF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s