Idea for this post was kindly suggested by real ADF BC guru and evangelist - Steve Muench. You can check famous ADF Not Yet Documented Examples on Steve's blog - Dive into ADF.
The main idea is about composite Unique Key, based on multiple EO attributes. Ideally, users should be allowed to change composite Unique Key values, without getting validation errors too early (before trying to save changes). However, this is not the case by default - and I will explain in this post, how to make it work properly with EntityLevelOnly = true property.
Sample application - ComplexUniqueKeyApp.zip, implements alternate key for two attributes from the EO. These attributes are Letter and Digit (SQL script to create required DB table is provided with the sample):
Based on alternate key, Unique Key validation rule is created for Letter and Digit:
Both attributes are set with AutoSubmit = true on the UI, to make sure new value will be submitted immediately:
DB table is populate with unique values for Letter and Digit columns. I could try to change first row and set B for Letter and 3 for Digit. Obviously, I would change one of the values first, if I'm going to change A to B - this could force ADF to raise Unique Key error (there is already B for Letter with Digit 1). So, Unique Key validation error would be generated too early, before I would change Digit to 3:
First row is rendered on UI, with A for Letter and 1 for Digit. I'm going to try to change A to B:
As soon as I would leave Letter field and try to move to Digit, ADF would raise validation error about broken uniqueness:
This behaviour can be improved with EntityLevelOnly = true property in EO definition class. Override standard method - addUniqueKeyValidation to catch Unique Key validation rule definitions. Here we could check by name and apply setEntityLevelOnly(true) method for our Unique Key validator:
Validation rule name:
Can be verified using actual validation rule definition in the EO (this could be made generic, if required):
With EntityLevelOnly = true applied, I can change first part of the Unique Key, and move to change second part of the key to set new unique value:
The main idea is about composite Unique Key, based on multiple EO attributes. Ideally, users should be allowed to change composite Unique Key values, without getting validation errors too early (before trying to save changes). However, this is not the case by default - and I will explain in this post, how to make it work properly with EntityLevelOnly = true property.
Sample application - ComplexUniqueKeyApp.zip, implements alternate key for two attributes from the EO. These attributes are Letter and Digit (SQL script to create required DB table is provided with the sample):
Based on alternate key, Unique Key validation rule is created for Letter and Digit:
Both attributes are set with AutoSubmit = true on the UI, to make sure new value will be submitted immediately:
DB table is populate with unique values for Letter and Digit columns. I could try to change first row and set B for Letter and 3 for Digit. Obviously, I would change one of the values first, if I'm going to change A to B - this could force ADF to raise Unique Key error (there is already B for Letter with Digit 1). So, Unique Key validation error would be generated too early, before I would change Digit to 3:
First row is rendered on UI, with A for Letter and 1 for Digit. I'm going to try to change A to B:
As soon as I would leave Letter field and try to move to Digit, ADF would raise validation error about broken uniqueness:
This behaviour can be improved with EntityLevelOnly = true property in EO definition class. Override standard method - addUniqueKeyValidation to catch Unique Key validation rule definitions. Here we could check by name and apply setEntityLevelOnly(true) method for our Unique Key validator:
Validation rule name:
Can be verified using actual validation rule definition in the EO (this could be made generic, if required):
With EntityLevelOnly = true applied, I can change first part of the Unique Key, and move to change second part of the key to set new unique value: