Skip to main content

Creating View Criteria having Bind Variables at run time

ADF BC let you to define View Criteria on the fly. In this post, I'm sharing some tips to create and populate criteria items with bind variables to implement the 'query-by-example' at run time.

The following code snippet illustrates the APIs to be used for creating View Criteria with Bind Variables.

String   attribName = "FirstName";
ViewObjectImpl voEmp = getEmployeesView1();

VariableValueManager vvm = voEmp.ensureVariableManager();

ViewCriteria vc = voEmp.createViewCriteria();
ViewCriteriaRow vcr = vc.createViewCriteriaRow();
ViewCriteriaItem vci = vcr.ensureCriteriaItem(attribName);

VariableImpl fstNameVar =

vci.setValue(0, ":dynamicBindVarAttribute");
vci.setIsBindVarValue(0, true);
vvm.setVariableValue(fstNameVar, "A%");


You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS2 + HR Schema].

A glance at the implementation.

This example contains a task flow 'dynamicVC-sample-tf-definition' with a default method activity which is wired to AppModuleImpl::demoDynamicVCWithBindVar(String attribName). This method (demoDynamicVCWithBindVar) creates ViewCriteria on the fly, based on the input parameter passed from the callee. Please take a look at the source ( relevant part is copied above for your reference ).

Learn More ...

There are a lot more points like this. If  you are curious to learn the internals of the ADF Business Components and ADF Binding Layer,  the following book is for you - Oracle ADF Real World Developer’s Guide.
More details about this book can be found in this post-

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…