Skip Headers

Oracle® Application Development Framework Developer's Guide 10g Release 3 (10.1.3) B25386-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# 13.4 Adding ADF Bindings to Tables

You can add ADF bindings to an entire table at one time. In fact, it is recommended to bind the entire table instead of the individual components that comprise the table. When you add a binding to a table, you can drag an entire collection from the Data Control Palette onto the table. You can bind an individual column, but only if the table is already bound to an iterator.

## 13.4.1 How to Add ADF Bindings to Tables

To add ADF bindings to a table, you drag a data collection from the Data Control Palette and drop it on the table 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 table:

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 table. 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. For example, if a column tag is selected, select the table tag instead.

3. From the Data Control Palette, drag a data collection returned by a method or an accessor method to the Structure window and drop it on the selected table tag.

4. On the Data Control Palette context menu, choose Bind Existing ADF Table or Bind Existing ADF Read-only Table. The Edit Table Column dialog appears, as shown in Figure 13-4.

   Figure 13-4 Edit Table Column Dialog

   The Display Label column in the dialog displays the placeholder column headings entered when the table was created. In the example, the placeholder column headings are First Name, Last Name, Email, and User ID. The Value Binding column displays the attributes from the data collection. The Component to Use column displays the types of components each table column will contain.

5. In the Edit Table Columns dialog, use the dropdowns in the Value Binding fields to select the attributes from the data collection to be bound to each column in the table, as shown in Figure 13-5. If placeholder column headings were entered when the table was created, match the attributes to the appropriate column headings. For example, if a column heading is First Name, you would select the `firstName` attribute from the Value Binding dropdown next to that column heading.

   Figure 13-5 Value Binding Dropdown in the Edit Table Columns Dialog

   Tip: If you need to add additional columns to the table, click New.

   For more information about tables, see Chapter 7, "Adding Tables".

## 13.4.2 What Happens When You Add ADF Bindings to a Table

Example 13-4 displays a table before the ADF bindings are added. The table defines four columns and uses static placeholder values as column headings: `First Name`, `Last Name`, `Email`, and `User ID`. The table also defines a range navigation of 15 rows, table banding, and a selection facet.

Example 13-4 ADF Faces Table Before ADF Bindings

    <af:table emptyText="No items were found" rows="15" banding="none"
                 bandingInterval="1">
         <f:facet name="selection">
                 <af:tableSelectOne/>
         </f:facet>
         <af:column sortable="false" headerText="First Name">
           <af:outputText value="#{row.col1}"/>
         </af:column>
         <af:column sortable="false" headerText="Last Name">
           <af:outputText value="#{row.col2}"/>
         </af:column>
         <af:column sortable="false" headerText="Email">
           <af:outputText value="#{row.col3}"/>
         </af:column>
         <af:column sortable="false" headerText="User ID">
           <af:outputText value="#{row.col4}"/>
         </af:column>
    </af:table>

Example 13-5 displays the same table after the `User` data collection returned by the `findAllStaff` method from the SRDemo data control was dropped on it. Notice that placeholder column headings have been replaced with a binding on the `findAllStaff1` iterator, but that the selection facet and banding from the original table remain intact. The range navigation value is replaced by a binding on the iterator, which manages the current row. The `rangeSize` binding property, which defines the number of rows can be set in the page definition file. For a description of each binding property, see Appendix B, "Reference ADF Binding Properties".

Some additional elements have been added to the table tag that enable the binding to populate the rows in the table and manage the current row. In each row of the table, the `sortable` attribute has been changed to `true`, which makes the table columns sortable.

Example 13-5 ADF Faces Table After ADF Bindings Are Added

    <af:table emptyText="#{bindings.findAllStaff1.viewable ? 'No rows yet.' : 'Access
                            Denied.'}"
              rows="#{bindings.findAllStaff1.rangeSize}" banding="none"
              bandingInterval="1"
              value="#{bindings.findAllStaff1.collectionModel}" var="row"
              first="#{bindings.findAllStaff1.rangeStart}"
              selectionState="#{bindings.findAllStaff1.collectionModel.
                                selectedRow}"
              selectionListener="#{bindings.findAllStaff1.collectionModel.
                                    makeCurrent}">
         <f:facet name="selection">
           <af:tableSelectOne/>
         </f:facet>
         <af:column sortable="true"
                    headerText="#{bindings.findAllStaff1.labels.firstName}"
                    sortProperty="firstName">
            <af:outputText value="#{row.firstName}"/>
         </af:column>
         <af:column sortable="true"
                    headerText="#{bindings.findAllStaff1.labels.lastName}"
                    sortProperty="lastName">
            <af:outputText value="#{row.lastName}"/>
         </af:column>
         <af:column sortable="true"
                    headerText="#{bindings.findAllStaff1.labels.email}"
                    sortProperty="email">
            <af:outputText value="#{row.email}"/>
         </af:column>
         <af:column sortable="true"
                    headerText="#{bindings.findAllStaff1.labels.userId}"
                    sortProperty="userId">
            <af:outputText value="#{row.userId}">
               <f:convertNumber groupingUsed="false"
                                pattern="#{bindings.findAllStaff1.formats.
                                   userId}"/>
            </af:outputText>
         </af:column>
    </af:table>

In addition to adding the bindings to the table, JDeveloper automatically adds entries for the databound table to the page definition file, as shown in Example 13-6.

The page definition entries include an iterator binding object defined in the `executables` element. Notice that the `RangeSize` property on the iterator is set to 10 by default. This value is now bound to the range navigation in the table and overrides the original range navigation value set in the table before the bindings were added. In the example, the original table set the range navigation value at 15. If necessary, you can change the `RangeSize` value in the page definition to match the original value defined in the table.

The `bindings` element contains a `methodAction`, which encapsulates information about how to invoke the method iterator, and value bindings for the attributes available to the table. The value bindings include all the attributes of the returned collection, even if the table itself is displaying only a subset of those attributes.

For more information about databound tables, see Chapter 7, "Adding Tables".

Example 13-6 Binding Objects Added to the Page Definition File for an ADF Faces Table

    <executables>
        <methodIterator id="findAllStaffIter" Binds="findAllStaff.result"
                        DataControl="SRPublicFacade" RangeSize="10"
                        BeanClass="oracle.srdemo.model.User"/>
    </executables>
    <bindings>
        <methodAction id="findAllStaff" InstanceName="SRPublicFacade.dataProvider"
                      DataControl="SRPublicFacade" MethodName="findAllStaff"
                      RequiresUpdateModel="true" Action="999"
                      ReturnName="SRPublicFacade.methodResults.SRPublicFacade_
                          dataProvider_findAllStaff_result"/>
        <table id="findAllStaff1" IterBinding="findAllStaffIter">
          <AttrNames>
            <Item Value="city"/>
            <Item Value="countryId"/>
            <Item Value="email"/>
            <Item Value="firstName"/>
            <Item Value="lastName"/>
            <Item Value="postalCode"/>
            <Item Value="stateProvince"/>
            <Item Value="streetAddress"/>
            <Item Value="userId"/>
            <Item Value="userRole"/>
          </AttrNames>
        </table>
    </bindings>