Showing posts with label DataProvider. Show all posts
Showing posts with label DataProvider. Show all posts

Friday, March 5, 2010

ADF Model: How to Programmatically Access the DataProvider Thing

"One of the 'power tools' of ADF Binding is the dataProvider attribute that pretty much every binding object supports." -Duncan Mills

Duncan Mills has a comprehensive blogpost about this DataProvider thing here. When I was still on my first steps in learning ADF, I found it a challenge to programmatically access this DataProvider thing without using the JSFUtils.resolveExpression() method, that is why I thought that maybe it would be helpful for others who are still beginning their Oracle ADF experience if I will post here what I have figured out.

    public Object getCurrentRowDataProvider(String iteratorName) {
        BindingContainer bindings = getBindings();
        DCIteratorBinding dcib =
            (DCIteratorBinding)bindings.get(iteratorName);
        RowSetIterator iter = dcib.getRowSetIterator();
        DCDataRow row = (DCDataRow)iter.getCurrentRow();
        return row.getDataProvider();
    }
    public BindingContainer getBindings() {
        return (BindingContainer)JSFUtils.resolveExpression("#{bindings}");
    }
Illustrative usage:
    public void save(ActionEvent event){
        Employee employee = (Employee)getCurrentRowDataProvider("findAllEmployeesIterator");
        //some other codes like setting some default properties for the employee
        ...
        //or accessing the object attributes from employee
        System.out.println(employee.getDepartment().getDepartmentName());
        //invoke saveEmployee methodAction
        OperationBinding oper = getBindings().getOperationBinding("saveEmployee");
        oper.execute();
    }
Cheers!