Wednesday, November 4, 2009

Groovy Validation Hint in Oracle ADF 11g

There is one very powerful option for Groovy validation in Oracle ADF 11g. This option is somehow hidden from developers and quite often not used. I decided to blog about it, in order to put some light on it. This option is about how to get old and new values for edited attribute. Groovy provides two reserved keywords - oldValue and newValue, you can use those keywords while writing Groovy validation script.

Download sample application - GroovyValidation.zip. This sample implements pretty simple validation rule, to demonstrate how you can use mentioned Groovy keywords:


Reserved keyword oldValue is used to implement validation logic:


Developer can specify token method expressions in validation failure message based on the same oldValue and newValue:


On runtime, if validation rule will fail, it will show current wrong value. If you will not use newValue, it will show currently in database stored value, which is not correct.

4 comments:

Grant Ronald said...

I wrote a paper on introduction to groovy
http://www.oracle.com/technology/products/jdev/11/how-tos/groovy/introduction_to_groovy.pdf

Hasim said...

I want validate email address using Groovy expression.

Renan Monteiro's Sharepoint said...

Hi friends!

The new link to Grant's paper is http://www.oracle.com/technetwork/developer-tools/jdev/introduction-to-groovy-128837.pdf

aldosilva6 said...

Hi Andrejus,

I'm getting an error using groovy expression on Error Message on JDeveloper12.2.1.2.0.

Compile Time Error: [Static type checking] - No such property: newValue for class:groovy.lang.Binding