Search This Blog

Accessing the ADF Binding Layer from Java

BindingContext and BindingContainer

BindingContext is a container object that holds a list of available data controls and data binding objects. It is the Java representation of all cpx files marked in your adfm.xml file. Whereas the BindingContainer class represents Java representation of the page definition file.

   import oracle.adf.model.BindingContext;
   import oracle.binding.BindingContainer;
   ...
   ...
    public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

The DCBindingContainer class exposes more methods than are defined by the BindingContainer interface.

import oracle.adf.model.binding.DCBindingContainer;
...
DCBindingContainer bindings = (DCBindingContainer)this.getBindings();

DCIteratorBinding
It is used to access the rowset iterator of a view object.

import oracle.adf.model.binding.DCIteratorBinding;
import oracle.jbo.Row;
...
DCBindingContainer bc = (DCBindingContainer) getBindings();
DCIteratorBinding iteratorBinding = bc.findIteratorBinding("DepartmentsIterator");
//Execute VO query by executing iterator
iteratorBinding.executeQuery();
//To gets the underlying view object for the iterator
//ViewObject vo = iteratorBinding.getViewObject();
Row currentRow = iteratorBinding.getCurrentRow();
OperationBinding

import oracle.binding.OperationBinding;
...
...
    public void updateDepartmentRow(Row currentDeptRow) {
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding("updateDepartments");
        operationBinding.getParamsMap().put("deptRow", currentDeptRow);
        Object returnValue = operationBinding.execute();
        if (operationBinding.getErrors().isEmpty()) {
            //No exception, Operation is success
        } else {
            //Exception is thrown from the method, handle it here
            //OperationBinding::getErrors() return list of JboException
            List errorList = operationBinding.getErrors();
            //Alternative path 'on error' go here
        }
    }

AttributeBinding

import oracle.binding.AttributeBinding;
...
...
AttributeBinding departmentName = (AttributeBinding) bindings.get("DepartmentName");


JUCtrlListBinding
To access the list binding from Java, you use the JUCtrlListBinding class, as shown next:

   import oracle.jbo.uicli.binding.JUCtrlListBinding;
   import oracle.jbo.domain.Number;
   ...
   JUCtrlListBinding listBinding = (JUCtrlListBinding) bindings.get("JobId");
   ViewRowImpl selectedListRow = (ViewRowImpl) listBinding.getSelectedValue();
   String jobIdValue = (String) selectedListRow.getAttribute("JobId");
   Number maxSalary = (Number) selectedListRow.getAttribute("MaxSalary");
 
JUCtrlHierBinding
The JUCtrlHierBinding class is used to bind tree, treetable, and table components to the ADF model.

JUCtrlHierBinding hierBinding = (JUCtrlHierBinding)bindings.get("EmployeesView3");
Access Parameter Binding

import oracle.adf.model.binding.DCBindingContainer;
...
...
    public String getPageParamater() {
        DCBindingContainer bindings = (DCBindingContainer)this.getBindings();
        Map map = bindings.getParametersMap();
        String name = map.get("name").toString();
        return null;
    }

Perform Delete and Commit by a single button click

Create a bean named DeleteCommitBean in UI project.

Add a method named onDeleteItem that calls the ADFUtil.invokeEL() helper method to execute the EL expression that you pass in as a parameter. In this case, it will execute a Delete and a Commit. Note that the Delete and Commit methods must be in the Page Definition Bindings for any page that uses them.
    public void onDeleteItem(ActionEvent actionEvent) {
        ADFUtil.invokeEL("#{bindings.Delete.execute}");
        ADFUtil.invokeEL("#{bindings.Commit.execute}");
        System.out.println("Deleted");
    }
Register the bean as managed bean in adfc-config.xml pageflow file.

In the UI, add a button from the Component Palette. Modify the text as Delete and set the ActionListener as
#{FODCommitDeleteBean.onDeleteItem}
You can also click on 'Edit' to modify the same.

Code snippet of invokeEL method in ADFUtil class
public class ADFUtil {

    public static Object invokeEL(String el) {
        return invokeEL(el, new Class[0], new Object[0]);
    }

    public static Object invokeEL(String el, Class[] paramTypes, Object[] params) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
        MethodExpression exp = expressionFactory.createMethodExpression(elContext, el, Object.class, paramTypes);
        return exp.invoke(elContext, params);
    }
}

  • FacesContext is a class that contains all of the per-request state information related to the processing of a single JSF request, and the rendering of the corresponding response. It is passed to, and potentially modified by, each phase of the request processing life cycle.
  • ELContext is a class that is used to evaluate an expression.
  • ExpressionFactory is a class that parses a String into a value expression or a method expression for later evaluation.

Pass Parameters inside an ADF Bounded Taskflow

So there is a 'home' page which is displaying the list of locations. User can either click on the location ID to update the record, or create a location by clicking Create button.

First define an input parameter 'Action' in the 'child' taskflow. Set its value as #{pageFlowScope.Action}.

Drag the CreateInsert operation to the task flow diagram to create a method call activity. Change fixed-outcome of the CreateInsert method call activity to done.

Add an expression to the router: #{pageFlowScope.Action == 'New'}



Now in the 'main' taskflow, click on the 'child' taskflow call and in the Property Inspector, set the value of the parameter as #{requestScope.Action}

Add a setPropertyListener property to the Create button. Set the From property to #{'New'}, To property to #{requestScope.Action} and Type as 'action'.

Download the sample application from File Cabinet: PassParaBoundTskflow.rar