Get the value from SelectOneChoice or LOV not the index in bean -Oracle ADF

Another approach i am sharing with you.Normally we want to get selectOneChoice value and we normally get the index.
We will creating an attribute in the selectOneChoice items and the selected value lable.

                        <af:selectOneChoice value="#{bindings.reportType.inputValue}"
                                          required="#{bindings.reportType.hints.mandatory}"
                                          shortDesc="#{bindings.reportType.hints.tooltip}"
                                          id="soc1" partialTriggers="cb2"
                                          autoSubmit="true"
                                          styleClass="hrt_reporting"
                                          valueChangeListener="#{pageFlowScope.ReportFilterBean.reportTypeVC}"
                                          binding="#{pageFlowScope.ReportFilterBean.reportTypeChoice}">
                        <f:selectItems value="#{bindings.reportType.items}"
                                       id="si2"/>
                        <f:attribute name="rowIndexVal" value="#{bindings.reportType.items[bindings.reportType.inputValue].label}"/>
                      </af:selectOneChoice>

and in the bean you can write as

        valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
        Map map = ((UIComponent)valueChangeEvent.getSource()).getAttributes();
        String reportTypeValue = (String)map.get("rowIndexVal");

that’s it, you are done.

Happy coding with Vinay Kumar in techartifact,,

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.

Don’t use managed bean , when you really don’t need it- Use Page Definition Variables in ADF

Requirement – to understand the concept of page variable for storing temporary page value.

Use Case- We have a check box and a table.on checking of checkbox we should show table otherwise we should not show the table.
Normally most of ADF developer will say– oh , its easy, they bind checkbox with managed bean and select the value of it and make visible true and false to table. But , in actual it impacts performance.You really don’t need a managed bean,Why you need to interact with model layer.You don’t need it.
You can create a page variable and store temporary page value.Most people don’t know about it or don’t know how to create it.Today we will discuss this.

i am assuming you have a HR schema and create a table and a checkbox.On checking of checkbox table should be visible.

Go to page definition file of page.Inside executable ,select variable and click insert inside variable like below

Now we will be creating binding for this variable.Click + on binding

Select attributValue and select variable as data source and attribute as Show Table, which we have created earlier.

Now our page defition file will look like this-

Select checkbox and bind value as #{bindings.ShowTable1.inputValue} and make autosubmit to true.
Go to table and put id of selectCheckbox to partial trigger of table.
Thats it .You have’nt used managed bean here. I think its more easy than this.Now run your page first it will look like this

Now Checked the checkbox

You are done.Now you know how to create page defition variable in page.Managed bean will not have less code.. 😀

Happy coding with Vinay Kumar in Techartifact ….