Thursday, April 4, 2013

Traversing ViewCriteria hierarchy

A ViewCriteria instance is an hierarchy of Criteria Rows and Criteria Items. Criteria Item is the smallest unit which contains an Operand, Operator and Value(Either Literal or Bind Variable).

A ViewCriteriaRow can have multipe ViewCriteriaItem instances and a ViewCriteria can have multiple ViewCriteriaRows. Let us assume appliedVC is an applied ViewCriteria to a ViewObject.


The below code snippet traverses the ViewCriteria and locates a particular ViewCriteriaItem and removes. Before removing it reads the value and stores it in a variable.



            boolean found = false;
            while (appliedVC.hasNext() && !found) {
                vcr = (ViewCriteriaRow)appliedVC.next();
                if (vcr != null) {
                   ViewCriteriaItem[] vcis = vcr.getCriteriaItemArray();
                   if (vcis != null && vcis.length > 0) {
                       for (int j = 0; j < vcis.length && !found; j++) {
                           ViewCriteriaItem vci = vcis[j];
                           if(vci!= null && vci.getAttributeDef()!=null && vci.getAttributeDef().getName().equals("MyFlag")){
                                System.out.println("****"+vci.getAttributeDef().getName()+"***"+vci.getValue());
                                if(vci.getValue()!=null){
                                    myFlagVal = vci.getValue().toString();
                                    vcr.removeCriteriaItem("MasterOrgFlag", vci);
                                    found=true;
                                }
                           }
                       }
                   }
                }
            }

No comments:

Post a Comment