You can control whether users can see and select a null (no value) entry in a picklist, combobox, or dropdown in the ViewModel Editor.
A picklist is the collection of values presented by a combobox or dropdown. The Null and NullRep settings determine how the control represents a missing selection. These settings affect the ViewModel control's presentation; they do not by themselves make the underlying attribute or reference nullable. For model-level nullability, see Allow Null.
Configure the null entry
- Open the ViewModel in ViewModel Editor.
- Select the picklist or combobox definition that supplies the available values.
- Set the Null option to choose whether and where the no-value entry appears.
- Enter the text to show for that entry in NullRep.
For example, for a color selector, set NullRep to Choose a color. A user then sees that text instead of a blank entry when the current value is null.
Null options
| Null option | What the user sees | Example use |
|---|---|---|
| None | No null entry is included in the picklist. The user can select only values supplied by the picklist. | Use for a required selection, such as a status that must always be set. |
| First | A null entry is available as the first item in the list. | Set NullRep to Choose a color. The first item is Choose a color, followed by the available colors. The user can return the selection to null.
|
| Last | A null entry is available as the last item in the list. | Set NullRep to No color. The colors appear first and No color appears at the end. The user can select it to clear the value.
|
| IfEmpty | The null text is shown while no value has been selected. After the user selects another item, the null entry is no longer available for selection. | Set NullRep to Choose a color. It guides a user who has not selected a color, but does not provide a later option to clear a selected color.
|
Choose the right option
Use None when the UI must not offer an empty choice. Use First or Last when users must be able to clear an optional selection after choosing a value. Use IfEmpty when you want placeholder text for an unset value but do not want users to select null after making a choice.
The text in NullRep is visible to users, so make it describe the meaning of no selection. For example:
Choose a colorfor an unset value that needs attention.No colorwhen no selection is a valid outcome.Not assignedfor an optional reference such as an owner.
Important distinction: display versus nullability
The Null setting controls whether the picklist presents a null choice. It does not override the model's ability to store no value. If the selected attribute must be able to hold no value, configure its nullability with Allow Null. Database defaults are configured separately; see DefaultDBValue.
When you work with null in OCL, use .isNull or .notNull to test for it. To assign a typed null, use nullValue.
Picklist behavior
A combobox matches selected objects, not only their displayed text. Ensure that the picklist contains the currently selected value. If it does not, the control can lose the displayed selection or show the wrong value. Also ensure that the collection used for the picklist is stable over time. See Documentation:The combobox for troubleshooting guidance.
For an MVC implementation of a model-driven ViewModel combobox, including the generated external identifier used for the selection round trip, see Documentation:Comboboxes in MVC from model driven ViewModel.
