Element Validation
Sometimes, just an attribute validation is not enough, you want to do a validation involving two or more attributes in your validation. This is supported by the ElementValidation annotation on a method in your Customization Java Class.Â
The ElementValidation is invoked at the end of the request during the validate of the DataControl. The ElementValidation throws an ValidationException.
Optional you can provide a list of attributes to limit firing when only specified attributes have changed.
@ElementValidation(attr = { "salary", "commissionPercentage" }) public void validateIfAttrChanged(XMLDCElement employee) { BigDecimal salary = (BigDecimal) employee.get("salary"); BigDecimal commissionPercentage = (BigDecimal) employee.get("commissionPercentage"); if (salary == null && commissionPercentage == null) { throw new ValidationException("Salary and commission percentage can not both be empty"); } }
Just like the AttributeValidation, at design time you don't notice the validation in the DataControl panel, but on run time it will be executed.
In the above example, the ElementValidation will only be invoked if the salary or the commissionPercentage field has changed. Â
The signature of the method is less specific, it does not need to start with the word validate, although we suggest you do.Â
For non existing attributes in the attr list an InvalidMethodSignatureException will be thrown.Â
As an argument to your method, you need to add the XMLDCElement representing you Element.Â
You need to add the annotation ElementValidation to you method, resulting in an import of the class 'org.adfemg.datacontrol.xml.annotation.ElementValidation'.
When the validation fails, it is up to the programmer to throw an oracle.jboValidationException. Â
When rebuilding the Java class and running the page, you will notice that clearing both the Salary field as well as the commissionPercentage will result in an error:Â