To keep it short - ADF BC Groovy keyword "
oldValue" and ADF BC API method
getPostedAttribute(index) are not the same thing. I spoke with ADF developer today, who have spent around 5 days debugging and hitting validation bug related to incorrect usage of "
oldValue" by Groovy. Both approached - "
oldValue" and
getPostedAttribute(index) are valid for its own use cases. But you should clearly understand the difference, otherwise may hit some painful bugs in validation rules.
How it works in ADF 11g R2:
1. "
oldValue" Groovy keyword returns
last valid value
2.
getPostedAttribute(index) returns value from database
In most of the cases, we need to compare user input against original value from the database. This makes Groovy "
oldValue" keyword pretty useless in such use cases where we want to validate data against original one.
Download sample application where both cases are demonstrated -
OldNewValueValidationApp.zip.
Sample application defines one validation rule for
CommissionPct attribute:
This rule is using Groovy oldValue and newValue keywords:
Second validation rule is defined for
Salary attribute, its based on Java method. We are going to call getPostedAttribute(index) method from there:
Here is the code sample for getPostedAttribute(index) invocation:
1. Test for Groovy
oldValue keyword
Initial value for CommissionPct is 0.1:
Change it to negative -0.1, this will trigger validation rule:
Old value is reported to be 0.1, this is correct. Now enter positive valid value 0.2:
Type -0.2 now, old value is reported as 0.2 - this is last valid value, but not the original value from database (we didn't commited yet our change to database):
2. Test for
getPostedAttribute(index) method
Initial value for Salary is 16000:
Change it to 300, validation error is shown and you can check that old value is reported as 1600 (correct):
Change to new valid value 17000 now:
Again change back to invalid 400 - old value is reported correctly, the one original from database 16000:
Comments
Post a Comment