Tuesday, May 10, 2011

Entity Object Custom Codes @ADF

Key Entity Objects Features and Events for Programmatic Business Logic


As Entity Object are supposed to be reused in many Application Modules, so they should not depend directly on a View Object Instance in any specific app module data control.To avoid this, entity object can use current application module instance's createViewObject() to create an instance of VO it requires.
Following code show how to access View object for validation.


// Sample entity-level validation method
public boolean validateSomethingUsingViewObject() {
Number numVal = getSomeEntityAttr();
String stringVal = getAnotherEntityAttr();
// Get the view object instance for validation
// Create a new name for the VO instance being used for validation
String name = "Validation_" + viewObjectDefName.replace('.', '_');
// Try to see if an instance of this name already exists
ViewObject vo = getDBTransaction().getRootApplicationModule()
.findViewObject(name);
// If it doesn't already exist, create it using the definition name
if (vo == null) {
vo = getDBTransaction().getRootApplicationModule()
.createViewObject(name,viewObjectDefName);
}
// Set it's bind variables (which it will typically have!)
vo.setNamedBindWhereClauseParam("BindVarOne",numVal);
vo.setNamedBindWhereClauseParam("BindVarTwo",stringVal);
vo.executeQuery();
if ( /* some condition */) {
/*
* code here returns true if the validation succeeds
*/
}
return false;
}

..............................
Reference: Developer’s Guide For Forms/4GL Developers

No comments:

Post a Comment