Showing posts with label operation binding. Show all posts
Showing posts with label operation binding. Show all posts

Wednesday, December 23, 2015

Fixing the Issue where getBindings() returns Null

Problem Statement:

Suppose we have a jspx page having a bounded task flow as region.


The taskflow starts with method activity as shown in the figure


If the method tries to access the some method binding using the getBinding() method, where get binding is defined as:

    public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

some binding method accessed as:
        OperationBinding op =
            (OperationBinding)getBindings().get("someMethodInAppModImpl");
        Object result = op.execute();

in this case, the BindingContext.getCurrent() would return the BindingContext but when trying to access getCurrentBindingsEntry(), this method would return null and as result the
 OperationBinding op =
            (OperationBinding)getBindings().get("someMethodInAppModImpl");

would throw null pointer exception

Solution:

Since the page starts with method having no pagedef difination the CurrentBindingsEntry always return null.

Make Sure you create binding for the default method as:


also the binding defined for the method shall have the method binding for the someMethodInAppModImpl you wish to access during execution.

Once page defination is defined, you can see the small little sign at the right bottom of the methodas


Please reach out in case of any further issues


Tuesday, May 13, 2014

populate af:table based on value selected from dropdown : using operation binding

In previous example, i demonstrated how to use parametrized query to populate the the adf table. Here i will achieve the same using operation binding

1. Create 2 view objects:
       a. DepartmentVO : select * from departments

         b. EmployeeDeptVO : select * from employee where department_Id-:dept where dept is a bind variable. Make sure to create its impl class

3. create following custom method in AppmodImpl:
 
 public void getEmployeeForDept(String deptId){
        ViewObjectImpl vo = (ApplicationRoleVOImpl)findViewObject("EmployeeDeptVO1");
        vo.setNamedWhereClauseParam("dept", deptId);
        vo.executeQuery();
    }

and add this method in the page def of the jspx

   

4. On jspx, drag and drop the departnmentvo as selectone choice component

make sure to use department name as display attribute

5. drag and drop the EmployeeDeptVO as adf table on page 

6. create attribute binding on the page def for departmentId(using this we can get the value selected in dropdown)



7. write following line in vcl of the drop down

        BindingContext bctx = BindingContext.getCurrent();
        BindingContainer bindings = bctx.getCurrentBindingsEntry();
        FacesContext contxt = FacesContext.getCurrentInstance();
        valueChangeEvent.getComponent().processUpdates(contxt);
        AttributeBinding applicationNameBinding =   (AttributeBinding)bindings.getControlBinding("DepartmentId");
        String DepartmentId= applicationNameBinding.getInputValue().toString();
        DepartmentId = applicationNameBinding.getInputValue().toString();
        System.out.println("DepartmentId Selected    " + DepartmentId);


        oracle.adf.model.OperationBinding op = (oracle.adf.model.OperationBinding)getBindings().get("getEmployeeForDept");
        op.getParamsMap().put("deptId", DepartmentId);
        Object result = op.execute();
        AdfFacesContext.getCurrentInstance().addPartialTarget(getEmployeeTable());

8. Once the application is run the table is populated based on the department selected in the department drop down