Skip Headers
Oracle® Application Development Framework Developer's Guide
10g Release 3 (10.1.3)
B25386-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

13.6 Adding ADF Bindings to Selection Lists

You can add ADF bindings to any of the selection lists previously shown in Table 13-1. A databound selection list displays values from a data control collection or a static list and updates an attribute in another collection or a method parameter based on the user's selection. When adding a binding to a list, you use an attribute from the data control that will be populated by the selected value in the list.

13.6.1 How to Add ADF Bindings to Selection Lists

To add ADF bindings to a selection list, you drag an attribute from the Data Control Palette and drop it on the selection list tag displayed in the Structure window. For general tips about dropping items from the Data Control Palette onto the Structure window, see Section 13.1.1, "How to Add ADF Bindings to Components Using the Data Control Palette".

To add ADF bindings to a selection list component:

  1. With the page displayed in the Design page of the visual editor, open the Structure window.

  2. In the Design page of the visual editor, select the selection list component. The tag selected in the Structure window must be one of the tags listed previously in Table 13-1. JDeveloper simultaneously selects the corresponding tag in the Structure window. If the incorrect tag is selected, make the adjustment in the Structure window.

  3. From the Data Control Palette, drag an attribute in a collection to the Structure window and drop it on the selected selection list tag. Use the attribute in the data collection that you want to populate when the user selects an item from the list.

  4. On the Data Control Palette context menu, choose Bind Existing <component name>.

  5. In the List Binding Editor, define the data collection that will be updated by the list (Base Data Source), the data collection that will populate the list (List Data Source), and the attributes that will be displayed in the list. For information about using the List Binding Editor to define lists, see Section 11.7, "Creating Databound Dropdown Lists".

13.6.2 What Happens When You Add ADF Bindings to a Selection List

Example 13-10 displays a single-selection dropdown list before the ADF bindings are added. Notice that the component defines a label for the list, but that it does not define static list item labels and values. The item labels and values will be populated by the bindings.

Example 13-10 ADF Faces Single-Selection Dropdown Before ADF Bindings

<af:selectOneChoice label="Product:"/>

Example 13-11 displays the same list after the prodID attribute in the Product collection from the SRDemo data control was dropped on it. The binding replaced the original label with a binding on the ProductprodId attribute, which was the attribute that was dragged from the Data Control Palette and dropped on the dropdown list component. You can change the label using control hints. The list values are also bound to the same attribute. Notice that no display values or labels are defined in the component by the binding. Instead, the display values are defined in the page definition file.


Tip:

Any static item labels and values defined in the original selection list are not replaced by the ADF bindings. If you add static item labels and values to the original selection list, and then add a dynamic list with a binding on the data collection, the list will display both the values populated by the binding and the static values defined in the component itself. In most cases, you would not want this. Therefore, you must either design the initial component without using static item labels and values, or remove them after the bindings are added.

Example 13-11 ADF Faces Single-Selection Dropdown After ADF Bindings Are Added

<af:selectOneChoice label="#{bindings.ProductprodId.label}"
                    value="#{bindings.ProductprodId.inputValue}">
    <f:selectItems value="#{bindings.ProductprodId.items}"/>
</af:selectOneChoice>

In addition to adding the bindings to the list, JDeveloper automatically adds several binding objects for the list to the page definition file, as shown in Example 13-12. The iterator binding objects in the executables element define the iterators that return the collection that populates the list, which in the example is findAllProduct, and the iterator that updates the target collection, which is createServiceRequestIter1. The bindings element contains two action binding objects, which encapsulate the information needed to invoke the methods that populate the list and update the data collection, including the method parameters. Notice that the value bindings include a ListDisplayAttrNames element, which defines the data collection attributes that populate the values the user sees in the list. This element is added only if the list is a dynamic list, meaning that the list items are populated by a binding on the data collection. If the list is a static list, a ValueList element is added instead with the static values that will appear in the list.

For more information about databound lists, see Section 11.7, "Creating Databound Dropdown Lists".

Example 13-12 Binding Objects Added to the Page Definition File for a Single-Selection Dropdown List

 <executables>
    <methodIterator id="createServiceRequestIter1"
                    Binds="createServiceRequest1.result"
                    DataControl="SRPublicFacade" RangeSize="10"
                    BeanClass="oracle.srdemo.model.ServiceRequest"/>
    <methodIterator id="findAllProductIter" Binds="findAllProduct.result"
                    DataControl="SRPublicFacade" RangeSize="-1"
                    BeanClass="oracle.srdemo.model.Product"/>
  </executables>
  <bindings>
    <methodAction id="findAllProduct"
                  InstanceName="SRPublicFacade.dataProvider"
                  DataControl="SRPublicFacade" MethodName="findAllProduct"
                  RequiresUpdateModel="true" Action="999"
                  ReturnName="SRPublicFacade.methodResults.SRPublicFacade_
                         dataProvider_findAllProduct_result"/>
    <methodAction id="createServiceRequest"
                  InstanceName="SRPublicFacade.dataProvider"
                  DataControl="SRPublicFacade"
                  MethodName="createServiceRequest" RequiresUpdateModel="true"
                  Action="999"
                  ReturnName="SRPublicFacade.methodResults.SRPublicFacade_
                        dataProvider_createServiceRequest_result">
      <NamedData NDName="problemDescription" NDType="java.lang.String"/>
      <NamedData NDName="productId" NDType="java.lang.Integer"/>
      <NamedData NDName="createdBy" NDType="java.lang.Integer"/>
    </methodAction>
    <methodAction id="createServiceRequest1"
                  InstanceName="SRPublicFacade.dataProvider"
                  DataControl="SRPublicFacade"
                  MethodName="createServiceRequest" RequiresUpdateModel="true"
                  Action="999"
                  ReturnName="SRPublicFacade.methodResults.SRPublicFacade_
                        dataProvider_createServiceRequest_result">
      <NamedData NDName="serviceRequests"
                 NDType="oracle.srdemo.model.ServiceRequest"/>
    </methodAction>
    <list id="ProductprodId" IterBinding="createServiceRequestIter1"
          StaticList="false" ListOperMode="0" ListIter="findAllProductIter">
      <AttrNames>
        <Item Value="product"/>
      </AttrNames>
      <ListAttrNames>
        <Item Value="dataProvider"/>
      </ListAttrNames>
      <ListDisplayAttrNames>
        <Item Value="name"/>
      </ListDisplayAttrNames>
    </list>
  </bindings>