< Previous | Next >

Lesson 2.4: Bind the Update button to an action binder

The Java visual editor provides action binders for calling a service on a data source when a button is clicked. For example, when the Update button is clicked, the application should run a modifyEmployee() method on the Web service with the changes entered into the details fields. In this lesson, you will bind the Update button to an action binder.

To bind the Update button:
  1. Select the Update button in the design area, and click the Bind tab to open the Component Action Bindings dialog box.

    Bind tab on Update button

  2. In the Source type field, select Web Service.
  3. In the Data source field, select webServiceDataSource.
  4. From the Source service list, select modifyEmployee(directory.service.FullEmployeeRecord).
  5. The Name field automatically changes to modifyEmployeeAction. Accept this default.
  6. In the Argument field, select selectedEmployeeRecord.
  7. Because the modifyEmployee() method takes a full employee record as its argument, you must leave the Property field blank.
  8. Set the Initial state of the button to Disabled.

    Component Action Bindings dialog box for Update button

  9. To define how the button changes its state, click Enablement rules. Specify that the button is enabled only when the argument's content is changed, and disabled in all other instances. Click OK.

    Enablement Rules dialog box for Update button

    This means that the Update button is disabled until the contents of the selectedEmployeeRecord changes. In other words, as soon as you type a new value in one of the details fields, which are bound to the selectedEmployeeRecord, the binder enables the button. If you select a new record or click Update, the button will become disabled again.

  10. Click OK.
A new SwingDataServiceAction binder is added for the Update button. If you select the button in the design area, the visual editor draws a line that indicates that the button is bound to the Web service data source. A pink, dotted arrow points from the selectedEmployeeRecord object to the line. This arrow indicates that the selectedEmployeeRecord is the argument for the call to the service.

Lesson checkpoint

Now, when you run the application, you can update an employee's record.

Select an employee in the table and change the last name. As soon as you change the last name, the Update button is enabled. When you click Update, the modifyEmployee service is called and the employee is updated. The new last name is reflected in the employees table.
< Previous | Next >