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!

4 comments:

  1. Hi, thanks for your post. I tried this piece. But i'm getting error at " return (BindingContainer)JSFUtils.resolveExpression("#{bindings}");"

    stating "resolveExpression" not found. May i know which util version util class is this.

    My jdev is 11.1.1.2.0 and getting JsfUtils.java not JSFUtils.java

    ReplyDelete
  2. Hi,
    You could get the must-have JSFUtils from the demo application of JDeveloper - the StoreFront demo (Fusion Order Demo)from this link: http://www.oracle.com/technology/products/jdev/samples/fod/index.html

    Regards,
    Pino

    ReplyDelete
  3. Thanks a lot Pino. Will Try that.

    ReplyDelete
  4. so cool blog! I really like it!

    ReplyDelete