1

I have a few questions regarding view criteria's

  1. After removing few applied view criteria's do I need to executeQuery before applying the same or new view criteria's?
  2. Also after applying each view criteria, do I need to executeQuery?
  3. If the first view criteria I want to apply is applied using 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();
Tony Stark
  • 434
  • 4
  • 13
Mike Reddington
  • 192
  • 2
  • 15

1 Answers1

1

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 :

  1. You do not need to executeQuery() if your vo is already set to be refreshed. If you have a ppr on the iterator for example. If not you need to executeQuery to force refresh your iterator.
  2. You do not need to executeQuery after each applyViewCriteria especially as you use the secondary boolean argument to true which "apply this view criteria on top of already applied view criteria". They will all apply over each other as layers and be set when you executeQuery at the end.
  3. If you do not add the secondary boolean argument as true, your view criteria will be the only one applied and all others would be automatically removed.
Cedric
  • 977
  • 2
  • 11
  • 23
  • Regarding the answer to question 1. Where to check if vo is already set to be refreshed, what is a ppr? Also, in my case after removing view criteria's I will immediately apply new view criteria's and execute the query. So, even if refreshed is set to false, I need no execute the query after removing view criteria's right? – Mike Reddington Jun 11 '21 at 05:16
  • 1
    PPR means partial page refresh in ADF. In your code I don't see any, so you should executeQuery at the very end. You do not need to remove old view criterias if you do not set the secondary boolean attribute to true. (See point 3). So yes, you only need applyViewCriteria(vc) and at the very end executeQuery() no need to remove view criterias and execute in the middle :) – Cedric Jun 11 '21 at 05:27