Fun with ADF BC Bind Parameters – Part Three: Support for generic bind-parameters in ADF Business Components

It can easily be the case that in your ADF BC application many ViewObjects make use of the same bind-parameters, for example a bind parameter referring to the current user. One simple way of providing the correct value for such bind-parameters could be implementing a little piece of pre-query-trigger-like logic: by extending the ViewObjectImpl class with our own implementation and overriding the executeQueryForCollection() method, we can intercept default query processing and set the value of any generic bind-parameters just prior to query execution, if they have not already been set.

Typical examples of generic bind-parameters are :currentUser and :locale, but you can think up any parameters you like, ranging from user preferences to security considerations. We could even go so far as to have our executeForQueryCollection method inspect all bind parameters, and try to get values for any parameter still without value from a central method on the ApplicationModuleImpl.

The implementation of this mechanism is fairly simple:....

First we create a generic ViewObjectImpl class that we will use as the foundation for all our ViewObjects. The class itself is implemented like this:

package nl.amis.model.adfbc;

import java.util.Locale;

import oracle.jbo.server.ApplicationModuleImpl;
import oracle.jbo.server.ViewObjectImpl;

public class GenericViewImpl extends ViewObjectImpl {
public GenericViewImpl() {
}

/**
* Overridden method
*/
protected void executeQueryForCollection(Object qc, Object[] params,
int numberOfParams) {

Locale locale = getApplicationModule().getSession().getLocale();
String currentUser =
((ApplicationModuleImpl)getApplicationModule()).getUserPrincipalName();
applyGenericBindParam(params, "language", locale.getLanguage());
applyGenericBindParam(params, "currentUser", currentUser);
super.executeQueryForCollection(qc, params, numberOfParams);
}


/**
* Looks in the params collection for a bind parameter with the indicated
* name. If the parameter exists and it does not have a (non-default) value,
* the paramValue is applied.
*
* @param params Collection of Bind Parameters (Where Clause Parameters)
* @param paramName The name of the generic bind parameter whose value is to be applied
* @param paramValue The value for the generic bind parameter under scrutiny
*/
private void applyGenericBindParam(Object[] params, String paramName,
Object paramValue) {
for (int i = 0; i < params.length; i++) {
if (paramName.equalsIgnoreCase((String)((Object[])params[i])[0])) {
// check for default value
if (("xx".equalsIgnoreCase((String)((Object[])params[i])[1]))) {
// now apply the generic value
((Object[])params[i])[1] = paramValue;
}
}
}
}


}
 

Then we configure this class to be the generic superclass for all ViewObjects in our ADF BC project:

Fun with ADF BC Bind Parameters - Part Three: Support for generic bind-parameters in ADF Business Components genericBinds genericVOImpl

Now let’s create a ViewObject that makes use of the generic :language bind variable:

Fun with ADF BC Bind Parameters - Part Three: Support for generic bind-parameters in ADF Business Components genericBinds jobsView

The bind variable is defined as follows:

Fun with ADF BC Bind Parameters - Part Three: Support for generic bind-parameters in ADF Business Components genericBinds bindLanguage

When we create a simple straightforward ADF Faces application with a SelectOneChoice compont based on this JobsView, the content of the dropdownlist adapts to the language set in the browser running the web application. We do not need any additional configuration for this, as the ADF mechanics ensure that the browser locale is made available to the ADF BC Session object and we have just made sure with our generic ViewObjectImpl that any occurrence of the language bind parameter that still has the meaningless default value set has the current locale’s language set.

Fun with ADF BC Bind Parameters - Part Three: Support for generic bind-parameters in ADF Business Components genericBinds webappDutch

and in English:

Fun with ADF BC Bind Parameters - Part Three: Support for generic bind-parameters in ADF Business Components genericBinds webappEnglish

Resources

JHeadstart Blog article on implementing horizontal authorization rules by adding filter conditions to the VO’s where-clause http://www.orablogs.com/jheadstart/howtos/HowToJ2EEAuthJHeadstart.htm#horizontal .

Steve Muench’s comparison between ADF BC framework methods and Oracle Forms trigger logic: http://www.oracle.com/technology/products/jdev/tips/muench/formstriggers/index.html#queryprocessing .

List of commonly used methods in ADF BC framework: http://www.oracle.com/technology/products/jdev/tips/muench/mostcommon/index.html#businesstiervo .