Namespace sap.ui.model.odata.typeModule: sap/ui/model/odata/type/ODataType
The types in this namespace are simple types corresponding to OData primitive types for both OData V2 and OData V4 (see "4.4 Primitive Types").
They can be used in any place where simple types are allowed (and the model representation matches), but they are of course most valuable when used in bindings to a sap.ui.model.odata.v2.ODataModel or sap.ui.model.odata.v4.ODataModel.
Example:
<Label text="ID"/> <Input value="{path : 'id', type : 'sap.ui.model.odata.type.String', constraints : {nullable : false, maxLength : 10}}"/> <Label text="valid through"/> <Input value="{path : 'validThrough', type : 'sap.ui.model.odata.type.DateTime', constraints : {displayFormat : 'Date'}}"/>
All types support formatting from the representation used in ODataModel ("model format") to various representations used by UI elements ("target type") and vice versa. Additionally they support validating a given value against the type's constraints.
The following target types may be supported:
Type | Description |
---|---|
string | The value is converted to a string , so that it can be displayed in an input field. Supported by all types. |
boolean | The value is converted to a Boolean , so that it can be displayed in a checkbox. Only supported by sap.ui.model.odata.type.Boolean. |
int | The value is converted to an integer (as number ). May cause truncation of decimals and overruns. Supported by all numeric types. |
float | The value is converted to a number . Supported by all numeric types. |
any | A technical format. The value is simply passed through. Only supported by format , not by parse . Supported by all types. |
All constraints relevant for OData V2 may be given as strings besides their natural types (e.g. nullable : "false"
or maxLength : "10"
). This makes the life of template processors easier, but is not needed for OData V4.
Handling of null
:
All types handle null
in the same way. When formatting to string
, it is simply passed through (and undefined
becomes null
, too). When parsing from string
, it is also passed through. Additionally, String and Guid convert the empty string to null
when parsing. validate
decides based on the constraint nullable
: If false
, null
is not accepted and leads to a (locale-dependent) ParseException
.
This ensures that the user cannot clear an input field bound to an attribute with non-nullable type. However it does not ensure that the user really entered something if the field was empty before.
Edm.Boolean
.Edm.Date
.Edm.DateTime
.Edm.DateTime
and Edm.DateTimeOffset
.Edm.DateTimeOffset
.Edm.Decimal
.Edm.Double
.Edm.Int16
or Edm.Int32
.Edm.Single
.Edm.String
.Edm.TimeOfDay
.