Applying ViewCriteria dynamically

If you want to Apply ViewCriteria by passing a parameter and then execute the VO query the following methods you can choose based on the requirement.

1) Getting VO from AppModule Instance Programmatically and Applying VC on it: Simply create a java class and register it as a managed bean and then inside the method get the AppModule instance and from which get VO  then apply VC and execute. [This method is not preferable as this might lead to creation of multiple AppModule instances]. shortcut to get the skeleton code is type bc4j and then press Ctrl+Enter inside java method.
Note: You need to close the AppModule instance connection at the end. Generally this will be placed in the finally section.

ApplicationModule am = null;
String amDef = "test.TestModule";
String config = "TestModuleLocal";
am = Configuration.createRootApplicationModule(amDef, config);
ViewObject vo = am.findViewObject("TestView");
// Work with your appmodule and view object here [Apply ViewCteria and execute VO]
finally {
if (null != am) {
Configuration.releaseRootApplicationModule(am, true);
am = null;
}
}

2.  Getting VO from Bindings programmatically and Applying VC on it: Simply create a java class and register it as a managed bean and then inside the method get the Iterator bindings [bindings should present in the page from which method is getting called] from which get VO then apply VC and execute. This is better method than previous method but still not much code efficient.


BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding itrBind = (DCIteratorBinding)bindings.get("EmployeesView1Iterator");
ViewObject empVO = itrBind.getViewObject();
empVO.clearCache();
ViewCriteriaManager vcm = empVO.getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria("EmployeesViewCriteria");
empVO.applyViewCriteria(vc);
empVO.setNamedWhereClauseParam("DeptId", 100);
empVO.executeQuery();

 

3. Create a method in AppModuleImpl class in which apply VC on VO and execute it before calling the page using Taskflow:

Generate AppModuleImpl class and then create a method inside the class and once coding is done then go to Client Interface of AppModule and move the created method to the client interface, so that it is visible in the data controls section of the AppModule and can be used in Taskflow or can be used in JSPX page also.

public void applyVC(){
ViewObject empVO = this.getEmployeesView1();
ViewCriteriaManager vcm = empVO.getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria("EmployeesViewCriteria");
empVO.applyViewCriteria(vc);
empVO.setNamedWhereClauseParam("DpetId", 100);
empVO.executeQuery();
}

Now all we need to do is execute the above method using Taskflow before the page is being called as we have to apply VC on VO and the results we have to display on the page.

 

 

 

Advertisements

‘RangeSize’property in ADF

If you want to get all the rows and show in a table or Iterator you need to set the property ‘RangeSize = -1‘ for the VO Iterator in the binding section and also you have to set the value of ‘rows’ property for the Table or Iterator being used to EL expression which points to ‘rangesize‘ of Iterator.

Eg:

 rows="#{bindings.EmployeesView1.rangeSize}"

By default the VO Iterator rows property will be set to 25 that means the rows from DB are fetched in a batches of 25. When you scroll down the table for every 25 rows you can see some delay and also a message showing like fetching rows. It is good to fetch and display only the rows how many are needed to show instead of fetching all the rows at once. If the table row count is small then you can set RangeSize = -1.

3

 

2

1