I have a few questions regarding view criteria's
testVO.applyViewCriteria(vc);
Do I need to unwanted remove view criteria's before or will applyViewCriteria(vc)
remove all existing view criteria's?What I'm trying to do in the below code is to remove any applied view criteria's and then apply new view criteria's that I want to apply.
testVO.getViewCriteriaManager().removeApplyViewCriteriaName("findByvc1");
testVO.getViewCriteriaManager().removeApplyViewCriteriaName("findByvc2");
testVO.getViewCriteriaManager().removeApplyViewCriteriaName("findByvc3");
//testVO.executeQuery();
ViewCriteria vc = testVO.getViewCriteriaManager().getViewCriteria("findByvc1");
VariableValueManager vm = testVO.ensureVariableManager();
vm.setVariableValue("vc1Var", 123);
testVO.applyViewCriteria(vc);
//testVO.executeQuery();
ViewCriteria vc1 = testVO.getViewCriteriaManager().getViewCriteria("findByvc3");
vm.setVariableValue("vc3Var", "test");
testVO.applyViewCriteria(vc1, true);
testVO.executeQuery();
Here's an article where I discuss how to apply view criteria programmatically in Oracle ADF : https://cedricleruth.com/how-to-apply-a-viewcriteria-programmatically-in-adf/ Code extract :
/**
* Apply view criteria named MyViewCriteria to it's ViewObject
* by getting it through the binding iterator MyViewObjectIterator
*/
public void applyViewCriteriaOnViewObjectByIteratorName(String MyViewCriteriaName, String MyViewObjectIteratorName) {
try {
//Get The viewObject from the iterator define in the current binding context
ViewObject vo = this.getViewObjectFromIteratorName(MyViewObjectIteratorName)
//Get all it's ViewCriteria using the ViewCriteriaManager of the ViewObject
ViewCriteriaManager vcm = vo.getViewCriteriaManager();
//Get the specified View Criteria
ViewCriteria vc = vcm.getViewCriteria(MyViewCriteriaName);
//Apply the ViewCriteria to the ViewObject
vo.applyViewCriteria(vc);
//Note: If you need to apply this view criteria on top of already applied view criteria
//without removing them you can add the following boolean parameter :
//vo.applyViewCriteria(vc,true);
//That's all you need if the iterator is set to be refresh after this
//If not you can force the ViewObject to execute by uncommenting the following :
//vo.executeQuery();
} catch (NullPointerException e) {
//Log and warn for null
//Often occur when there is an error in the provided attributes
//(MyViewCriteriaName, MyViewObjectIteratorName)
} catch (Exception e) {
//Log and warn for other exceptions - Should never be needed
}
/**
* Useful function to get ViewObject from IteratorName
* The iterator need to have a least one binding define in the current page
* In this gist it's a private but i advice setting it as a public static in an utility class available for the whole Controller
*/
private ViewObject getViewObjectFromIteratorName(String MyViewObjectIteratorName) {
ViewObject vo = null;
try {
DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterator = bindings.findIteratorBinding(MyViewObjectIteratorName);
vo = iterator.getViewObject();
} catch (NullPointerException e) {
//Log and warn for null
//Often occur when there is an error in the provided attributes
//or if the iterator doesn't have a least one binding define in the current page
}
return vo;
}
To answer your questions :