Illustrating the Use of Subclasses with the CapturePerson Form

The CapturePerson form shows an instance of a Person together with his or her address. The form contains a separate pane per Address class. The form configures itself dynamically to accommodate inbound address that are instances of Address or instances of a subclass thereof.

Procedure

  1. In the Form Designer, use Form > Properties view > Preview Data > Custom to select test data containing persons with a CanadianAddress, UKAddress, and USAddress, respectively.
  2. Observe the different results under the GWT Preview tab.

    The form displays a Xx Address(person_xxAddress) pane containing the fields appropriate to the Address subclass in question, including fields inherited from the base class Address and additional fields defined in the subclass.

    Results

Result

  • The Address Type optionlist provides a means to change the address type on the fly. In the Properties tab of the Properties view for this control, Custom Values are the fully qualified class names of all available address classes together with appropriate labels.

    Changing the selection of the Address Type optionlist fires the Change Address Type rule, which contains two actions.

  • The Change Address Type action determines whether the person's current address type matches the optionlist value. If it does not, it creates a new address and replaces the old address with the new one, preserving the values of inherited fields.
  • The Configure Address Panes action refreshes the user interface to match the address type in the model. It shows the pane appropriate to the address type and hides the others. It sets the value of the visible address pane to the address and the values of the invisible panes to null.
  • The Form Load rule fires when the form is loaded and initializes the value of the Address Type optionlist. This in turn fires the Change Address Type rule to configure the user interface to suit the initial address type.
  • Bindings on controls within the four address panes propagate values between the fields and the model.