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