Oracle ADF – Using the variables iterator from pages data bindings

February 4th, 2011 | Posted by in Oracle ADF | 2 Comments

This post shows how to use the variables iterator which is available in the ADF page definition. These variables could be used when the dynamic information from a particular page are not persisted but only saved temporally for custom processing in a managed bean.

For this purpose I have created a basic application which has a form where you could calculate the sum of two numbers.

The main page:

If you are selecting the “Sum” button the page should display the sum of the two numbers:

The form has two input text fields for the two operands, one button for the operation and finally an output text for the result.
The question is how to bind these to the page definition in order to work with them in the managed bean in order to have the lowest coupling between the view and the managed bean (view model).
One solution is to create variables and attributes in the page definition descriptor and bind them together. These attributes are accessible in the ADF page through EL in the form:
The page definition source is listed below:

    <variableIterator id="variables">
      <variable Name="number1" Type="oracle.jbo.domain.Number"/>
      <variable Name="number2" Type="oracle.jbo.domain.Number"/>
      <variable Name="result" Type="oracle.jbo.domain.Number"/>
    <attributeValues IterBinding="variables" id="Number1">
        <Item Value="number1"/>
    <attributeValues IterBinding="variables" id="Number2">
        <Item Value="number2"/>
    <attributeValues IterBinding="variables" id="Result">
        <Item Value="result"/>

In order to add a variable to the variables iterator in the JDeveloper IDE you should go to the ADF page definition overview and right-click on the “variables” item available in the “Executables” column and from the popup menu select the “Insert inside variables -> variable” sub-menu.
Then, you can add the attributes corresponding to these variables in the “Bindings” column by using the “+” button.
Below you have the page definition overview:

Now, if you open the Structure window you will see the newly created variables:

The page contains the following source code:

  <af:form id="f1">
        <af:panelStretchLayout id="psl1">
          <f:facet name="center">
            <af:panelFormLayout id="pfl1">
              <f:facet name="footer">
                <af:group id="g1">
                  <af:commandButton text="Sum" id="cb1"
                  <af:panelBorderLayout id="pbl1">
                    <f:facet name="start">
                      <af:outputLabel value="Result:" id="ol1"/>
                    <f:facet name="bottom"/>
                    <f:facet name="end"/>
                    <f:facet name="top"/>
                    <af:outputText value="#{bindings.Result.inputValue}" id="ot1"/>
              <af:inputText label="Number 1" id="it1" rows="1" columns="20"
              <af:inputText label="Number 2" id="it2" columns="20"

The source code corresponding to the #{Calculator.sum} EL-expression from the managed bean is:

    public String sum() {

      FacesContext context = FacesContext.getCurrentInstance();
      Application app = context.getApplication();
      DCBindingContainer binding = (DCBindingContainer) app.evaluateExpressionGet(context, "#{bindings}",DCBindingContainer.class);
      AttributeBinding attrNumber1 = (AttributeBinding)binding.getControlBinding("Number1");
      AttributeBinding attrNumber2 = (AttributeBinding)binding.getControlBinding("Number2");
      AttributeBinding attrResult = (AttributeBinding)binding.getControlBinding("Result");

      Number number1 = (Number)attrNumber1.getInputValue();
      Number number2 = (Number)attrNumber2.getInputValue();
        return null;

Tags: , , ,

2 Responses to “Oracle ADF – Using the variables iterator from pages data bindings”

  1. Arunkumar says:

    Good Example for ADF Beginners.

  2. Vlad says:


Leave a Reply