ADF BC Groovy keyword "oldValue" and ADF BC method getPostedAttribute(index)are not the same thing.
In ADF 11g R2, oldValue returns last valid value while getPostedAttribute(index) returns value from database. In the following, I will present two examples illustrating the difference between these expressions.
Using Groovy keyword "oldValue"
You should use oldValue whenever you want to retrieve an attribute's last valid value. In the following example,
we will create a validator which compares the newly entered Salary with the last verified one.
We can use parameters in the Failure Handling message.The Groovy keyword newValue returns the newly entered value.

First we create a validation rule for the CommissionPct attribut.
In ADF 11g R2, oldValue returns last valid value while getPostedAttribute(index) returns value from database. In the following, I will present two examples illustrating the difference between these expressions.
Using Groovy keyword "oldValue"
You should use oldValue whenever you want to retrieve an attribute's last valid value. In the following example,
we will create a validator which compares the newly entered Salary with the last verified one.
We can use parameters in the Failure Handling message.The Groovy keyword newValue returns the newly entered value.
When we run the application module, the initial value for Salary is 24000.
We change it into 40000 which is a correct value but we don't commit the change to the database.
We change Salary value a second time. We put 30000 which is less than the previous value. We get in this case our error message. You can see that the "oldValue" Groovy keyword returns the last valid value which is 40000 and not the original one which was 24000.
Using getPostedAttribute(index) method
You should use getPostedAttribute(index) when you want to retrieve the value stored in the database. In the following example, we will create a method validation rule which compares the newly entered CommissionPct with the original value saved in the database.

First we create a validation rule for the CommissionPct attribut.
This validation rule is based on a Java method named validateCommissionPct. inside which we are going to call getPostedAttribute(index) method that enables to get the original value of the attribut.
We define the failure Handling message.
Here is the code sample that invokes getPostedAttribute(index) method.
When we run the application module, the original value for
CommissionPct is 0.1.
If we change it to 0 we get our error message. the validation method compares it to the original value saved in the database.
You can download this sample from the link below: (it uses the HR demo schema which you can find an sql file here)
GroovyOldAndNewValue.rar (14ko)









