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.5 Adding ADF Bindings to Actions

You can add ADF bindings to buttons or links. When you add a binding to a button or link, you use a method or operation from the data control. When a user clicks the button or link, the method or operation is invoked.

If you want the button or link to perform page navigation, after adding the ADF binding you must bind the action attribute of the component tag to a backing bean, which will handle the navigation. The backing bean must inject the ADF binding container and return an outcome value. For information about creating navigation rules and binding navigation components to backing beans, see Chapter 9, "Adding Page Navigation Using Outcomes".

13.5.1 How to Add ADF Bindings to Actions

To add ADF bindings to a button or link, you drag a method or operation from the Data Control Palette and drop it on the button or link 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 button or link:

  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 button or link. 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 a method or operation to the Structure window and drop it on the selected button or link tag.

  4. On the Data Control Palette context menu, choose Bind Existing CommandButton or Bind Existing CommandLink.

  5. If the method requires a parameter, the Action Binding Editor appears where you define the parameter values to pass to the method. (For more information about passing parameters to methods, see Chapter 10, "Creating More Complex Pages".)

13.5.2 What Happens When You Add ADF Bindings to an Action

Example 13-7 displays a command button before the ADF bindings are added.

Example 13-7 ADF Faces Command Button Before ADF Bindings

<af:commandButton text="Display User"/>

Example 13-8 displays the same button after the findAllStaff() method from the SRDemo data control was dropped on it. The findAllStaff method returns the User collection. The binding replaced the original button label with the name of the method; you can change the button label using the Property Inspector. An actionListener attribute was added with a binding on the findAllStaff method. The actionListener detects when the user clicks the button and executes the method as a result. If you want the button to navigate to another page, you can bind to a backing bean or add an action value. For more information, see Chapter 9, "Adding Page Navigation Using Outcomes".

Example 13-8 ADF Faces Command Button After ADF Bindings Are Added

<af:commandButton text="findAllStaff"
                  actionListener="#{bindings.findAllStaff.execute}"
                  disabled="#{!bindings.findAllStaff.enabled}"/>

In addition to adding the bindings to the button, JDeveloper automatically adds a methodAction binding object to the page definition file, as shown in Example 13-9.

Example 13-9 Binding Object Added to the Page Definition File for a Command Button

<bindings>
    <methodAction id="findAllStaff" InstanceName="SRPublicFacade.dataProvider"
                  DataControl="SRPublicFacade" MethodName="findAllStaff"
                  RequiresUpdateModel="true" Action="999"
                  ReturnName="SRPublicFacade.methodResults.SRPublicFacade_
                      dataProvider_findAllStaff_result"/>
</bindings>

For more information about databound buttons and links, see Chapter 6, "Creating a Basic Page".