Monthly Archives: May 2013

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

Two Ways to Evaluate a Memory Scope Attribute Using Expression Language

All of us know how to evaluate a memory scope attribute using a dot notation syntax of the expression language.

Example: to access a request scope attribute, we use this syntax.

#{requestScope.attributeKey}

However, this syntax fails if the key has a dot (.) in its name. To overcome this limitation, expression language offers the string argument notation.

Example: to access a request scope attribute which has a (.) in its name, we use this syntax.

#{requestScope['attributeKey']}

 

1 Comment

Filed under ADF