Master Detail iterations using tree component by managed bean

Requirement – Making sort of master detail iteration by selecting tree node and refresh another table in same page.

Solutions- This application is based on default HR schema. Using country view we are making an tree. When we select any of county node in tree, all location respective to countries will display to right side.Note- we don’t have any view link between both VO.

Drag drop countries VO as tree.

We have a view criteria in locationVO and we drag drop locationVO on to the page as table.
On country tree we have selecionListener , which return selected the current row of tree.Code is as below –

    public void selectionListener(SelectionEvent selectionEvent) {
        // Add event code here...
        //##{bindings.checklistStructureVO1.treeModel.makeCurrent}
        invokeMethodExpression("#{bindings.CountriesView1_1.treeModel.makeCurrent}", Object.class, SelectionEvent.class, selectionEvent);
        
        RichTree tree = (RichTree)selectionEvent.getSource();
           TreeModel model = (TreeModel)tree.getValue();      
           //get selected nodes
           RowKeySet rowKeySet = selectionEvent.getAddedSet();
        Iterator rksIterator = rowKeySet.iterator();
        //Validating for single select only. Need to check for multiselect
        while (rksIterator.hasNext()) {
            List key = (List)rksIterator.next();
            JUCtrlHierBinding treeBinding = null;
            CollectionModel collectionModel = (CollectionModel)tree.getValue();
            treeBinding = (JUCtrlHierBinding)collectionModel.getWrappedData();            
            JUCtrlHierNodeBinding nodeBinding = null;
            nodeBinding = treeBinding.findNodeByKeyPath(key);
            Row rw = nodeBinding.getRow();
      
            String country = (String)rw.getAttribute("CountryId");
           
            Map pageFlowScope = ADFContext.getCurrent().getPageFlowScope();
             pageFlowScope.put("countryId", country);
             
            BindingContainer bindings = getBindings();
        
         OperationBinding ob1 = bindings.getOperationBinding("executeSearchVo");
     
           ob1.getParamsMap().put("country", country);
       
           Object result = ob1.execute();
        
           if (!ob1.getErrors().isEmpty()){
              List errorList = ob1.getErrors();
               System.out.println("ERROR IN VC EXECUTION");
            //g Capture and handle Error
          }   
        
        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getPbBinding());
    }
}

In the above method we are calling a custom appModuleImpl method and passing parameter to viewCriteria to location VO.We are also doing PPR programmaticly.

custom method of executing view Criteria –

    public void executeSearchVo(String country) {
        System.out.println("hello ob1"+ country);
    ViewObjectImpl traineeVO = this.getLocationsView1(); //relaventVO
    traineeVO.setApplyViewCriteriaName("LocationsViewCriteria");
    traineeVO.setNamedWhereClauseParam("country", country); //bindVariable name and pass value

     //criteriaName

    traineeVO.executeQuery(); //executeVO with Criteria

    }

That’s it. Now when you run the application it will look like as below –

You can download the sample application in below link.

TreeIteration

you are done. Happy coding with Vinay Kumar in Techartifact.