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
Excellent job!
ReplyDelete