Follow by Email

Saturday, 3 June 2017

oracle.jbo.domain.DataCreationException: JBO-25009 while using multiple selection component in ADF Faces


Previously I have posted about using multi-selection components (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle) of ADF Faces. These components make use of list binding and work on base attribute and display attribute concept


Blog readers mentioned that they are not able to use string value as base attribute in multi-select components so I have checked same in Jdeveloper 12.1.3
I have created selectManyCheckbox component using Departments table of HR Schema with this configuration



On running this, it throws an error 

oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:java.lang.Integer from type:java.lang.String with value:IT

Here IT is selected department now if we use DepartmentId as base attribute then it works smoothly but in that case, this code returns DepartmentId not name
So to get selected DepartmentName while using DepartmentId as base attribute we need to do a small change in code and component configuration is this


Changed Bean Code to get value-


import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.binding.BindingContainer;

import oracle.jbo.Row;
import oracle.jbo.ViewObject;
import oracle.jbo.uicli.binding.JUCtrlListBinding;

    /**Generic Method to get BindingContainer of current page,
     * fragment or region**/
    public BindingContainer getBindingsCont() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }


    /**Method to get selected value and description from multiselect component
     * @param actionEvent
     */
    public void getValue(ActionEvent actionEvent) {

        //Get Binding Container of Page
        BindingContainer bc = this.getBindingsCont();
        //Get multiselect component binding from pagedef
        JUCtrlListBinding listBindings = (JUCtrlListBinding) bc.get("DepartmentsVO11");
        //Get Selected Values (It'll return base value that is DepartmentId)
        Object str[] = listBindings.getSelectedValues();

        //Get Iterator of listbinding
        DCIteratorBinding iter = (DCIteratorBinding) getBindingsCont().get("DepartmentsVO1Iterator");
        //Get ViewObject instance from iterator
        ViewObject deptVo = iter.getViewObject();

        //Iterate over selected values
        for (int i = 0; i < str.length; i++) {
            System.out.println("Department Id- " + str[i]);
            //Filter ViewObject using DepartmentId
            Row filteredRows[] = deptVo.getFilteredRows("DepartmentId", str[i]);
            //Get DepartmentId from filtered row
            if (filteredRows.length > 0) {
                System.out.println("Department Name- " + filteredRows[0].getAttribute("DepartmentName"));
            }
        }
    }

Now run and check application

On button click-

Cheers :) Happy Learning

No comments :

Post a Comment