The property binding automatically determines the appropriate type depending on the property's metadata, unless a type is specified explicitly. For example, the binding "{DeliveryDate}"
will determine the type sap.ui.model.odata.type.DateTimeOffset
(assuming the metadata specifies "Edm.DateTimeOffset" for this property), but "{path : 'DeliveryDate', type : 'sap.ui.model.odata.type.String'}"
uses the hardcoded type sap.ui.model.odata.type.String
instead (and does not require metadata). You cannot specify format options or constraints unless you also hardcode the type.
Automatic type determination will take constraints from metadata into account, namely the OData property facets "MaxLength", "Nullable", "Precision" and "Scale". In addition to the OData property facets, the following OData V4 annotations are considered to set type constraints on automatic type determination:
-
Org.OData.Validation.V1.Validation.Minimum
,Org.OData.Validation.V1.Validation.Maximum
andOrg.OData.Validation.V1.Validation.Exclusive
are used to set the constraintsminimum
,maximum
,minimumExclusive
andmaximumExlusive
forsap.ui.model.odata.type.Decimal
. -
com.sap.vocabularies.Common.v1.IsDigitSequence
is used to set the constraintisDigitSequence
forsap.ui.model.odata.type.String
.
Only constant expressions are supported to determine the annotation value in this case.
Currently, the types "Edm.Boolean", "Edm.Byte", "Edm.Date", "Edm.DateTimeOffset", "Edm.Decimal", "Edm.Double", "Edm.Guid", "Edm.Int16", "Edm.Int32", "Edm.Int64", "Edm.SByte", "Edm.Single", "Edm.String" and "Edm.TimeOfDay" are supported and mapped to the corresponding type in the namespace sap.ui.model.odata.type
. All other types, including collections, are mapped to the generic type sap.ui.model.odata.type.Raw
which can only be used to access the raw model value "as is", but not to convert it to a human readable representation. This allows specialized controls to work with types that would otherwise not be supported.
For more information, see the sap.ui.model.odata.type and sap.ui.model.odata.type.Raw API documentation in the Demo Kit.
By default, a property binding delivers a value formatted according to the target type of the control property it applies to, for example, "boolean" in case of
<Icon src="sap-icon://message-warning" visible="{path : 'DeliveryDate', formatter : '.isOverdue'}">
. This leads to errors because type determination adds the correct type for theDeliveryDate
property which isDateTimeOffset
and cannot format its value as a boolean value. In such cases, usetargetType : 'any'
as follows:<Icon src="sap-icon://message-warning" visible="{path : 'DeliveryDate', targetType : 'any', formatter : '.isOverdue'}">In rare cases, you might also want to specify a different
targetType
, for examplestring
,boolean
,int
, orfloat
. For more information how these values relate to OData types, see the sap.ui.model.odata.type API documentation or explore the XML Templating: UI5 OData Types sample in the Demo Kit. For more information abouttargetType
, see the sap.ui.base.ManagedObject#bindProperty API documentation in the Demo Kit.