09 July, 2012

Add Validation at Runtime in ADF


An user request the below requirement.
He want to change validation condition in specific attribute at Entity Object at runtime.

For example there is a maximum of employee salary which can be changed at runtime, therefore the user doesn't want the maximum salary of employee to be fixed.

So I will create a new method for setting Validation Expression at runtime using Groovy.

   public void addExpressionValidator(AttributeDef attributeDef, String groovyExpression, String errorMessage) {  
     //create new ExpressionValidator  
     JboExpressionValidator jboExpressionValidator = new JboExpressionValidator(false, groovyExpression);  
   
     //Set an error message  
     jboExpressionValidator.setErrorMsgId(errorMessage);  
   
     //adding the validator to the attribute  
     ((AttributeDefImpl)attributeDef).addValidator(jboExpressionValidator);  
   
   }  



You should import the following classes
 import oracle.jbo.rules.JboExpressionValidator;  
 import oracle.jbo.server.AttributeDefImpl;  
 import oracle.jbo.AttributeDef;  


Calling Method
You can call  the previous method and pass validation to it  as below

   public void callMethod() {  
     AttributeDef attributeDef = getViewObject().findAttributeDef("attributeName");  
     addExpressionValidator(attributeDef, "newValue <= 25000", "Salary must less than 25000");  
   }  


Thanks

1 comment:

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...