Using Enumerations as Choices in an Optionlist or Radiogroup

You can use enumerations in a business object model and associated forms.

You can then specify choices for optionlists or radiogroups in the form with enumerations defined in the business object model.

Sample Project

To view the sample for this task, import the advanced sample projects as described in Importing the Forms Advanced Samples. The sample forms and business object model for the task described in this section are contained in the forms.samples.bom sample project.

The form for this task (CapturePreferences.form) is at:

   forms.samples.bom/Forms/BOMHowTo/BOMHowToProcess/
      CapturePreferences/

The business object model (FormsSamplesBOM.bom) is at:

   forms.samples.bom/Business Objects/

Procedure

  1. Double-click the form and business object model filenames (as well as those of other project resources) in the Project Explorer to open them in the editor.
  2. In the project editor, examine their contents, and use them as models for your own projects.

Result

Result

The business object model in the forms.sample.bom project models a Person class, a Preferences class, and three enumerations, Gender, Colour, and Beverage. There is a unidirectional composition association Person::preferences : Preferences[0..1]. (There are also some other types in the business object model that are not used in the present task, but pertain to other advanced task examples that also use this business object model.)

The CapturePreferences form shows a Person, his or her personal details, and preferences.

The Gender radiogroup choices are defined by the Person::gender : Gender[1] BOM feature, and the control is flagged as required to reflect the non-optional multiplicity of the feature. In the Properties tab of the Properties view, you can see the external reference to the Gender enumeration and the choice labels and values implied by that enumeration's literals. The enumeration literals' labels and values in the business object model are automatically reused in the form.

The Favourite Colour optionlist is bound to the corresponding Preferences::favouriteColour : Colour[1] feature. The feature is mandatory and the control is flagged as required. The choices are defined by the literals of the Colour enumeration.

The Favourite Drink optionlist is bound to the corresponding Preferences::favouriteDrink : Beverage[0..1] feature. Again, choice labels and values come from the BOM. This time, however, the feature is optional and the control is not flagged as required. The Properties tab shows an additional choice (unset); this is only generated for a control that is not required.