官术网_书友最值得收藏!

Using getPostedAttribute() to determine the posted attribute's value

There are times when you need to get the original database value of an entity object atttribute, such as when you want to compare the attribute's current value to the original database value. In this recipe, we will illustrate how to do this by utilizing the getPostedAttribute() method.

Getting ready

We will be working on the SharedComponets workspace. We will add a helper method to the custom entity framework class.

How to do it...

  1. Start by opening the SharedComponets workspace. If needed, follow the steps in the referenced recipe to create it.
  2. Locate the custom entity framework class and open it into the source editor.
  3. Add the following code to the custom entity framework class:
    /**
    * Check if attribute's value differs from its posted value
    * @param attrIdx the attribute index
    * @return
    */
    public boolean isAttrValueChanged(int attrIdx) {
      // get the attribute's posted value
      Object postedValue = getPostedAttribute(attrIdx);
      // get the attribute's current value
      Object newValue = getAttributeInternal(attrIdx);
      // return true if attribute value differs from its posted value
      return isAttributeChanged(attrIdx) &&((postedValue == null && newValue != null) ||(postedValue != null && newValue == null) ||(postedValue != null && newValue != null &&!newValue.equals(postedValue)));
    }

How it works...

We added a helper method called isAttrValueChanged() to the our custom entity framework class. This method accepts the attribute's index. The attribute index is generated and maintained by JDeveloper itself. The method first calls getPostedAttribute() specifying the attribute index to retrieve the attribute value that was posted to the database. This is the attribute's database value. Then it calls getAttributeInternal() using the same attribute index to determine the current attribute value. The two values are then compared. The method isAttributeChanged() returns true if the attribute value was changed in the current transaction.

The following is an example of calling isAttrValueChanged() from an entity implementation class to determine whether the current value of the employee's last name differs from the value that was posted to the database:

super.isAttrValueChanged(this.LASTNAME);

See also

  • Breaking up the application in multiple workspaces, Chapter 1, Pre-requisites to Success: ADF Project Setup and Foundations
  • Setting up BC base classes, Chapter 1, Pre-requisites to Success: ADF Project Setup and Foundations
主站蜘蛛池模板: 盐山县| 丰原市| 垣曲县| 沅陵县| 山西省| 广州市| 五莲县| 荣成市| 鄢陵县| 伊金霍洛旗| 大荔县| 永仁县| 清原| 丹江口市| 凤台县| 社会| 乐亭县| 天长市| 河南省| 社旗县| 静宁县| 南漳县| 竹溪县| 雷波县| 民县| 仁布县| 前郭尔| 宝山区| 九寨沟县| 泰宁县| 左云县| 石渠县| 恩平市| 胶南市| 湘潭市| 开封县| 抚远县| 岗巴县| 甘孜县| 石狮市| 繁昌县|