Namespace sap.ui.model.odata.AnnotationHelperModule: sap/ui/model/odata/AnnotationHelper
A collection of methods which help to consume OData V4 annotations in XML template views. Every context argument must belong to a sap.ui.model.odata.ODataMetaModel
instance.
Formatter functions like format and simplePath can be used in complex bindings to turn OData V4 annotations into texts or data bindings, e.g. <sfi:SmartField value="{path : 'meta>Value', formatter : 'sap.ui.model.odata.AnnotationHelper.simplePath'}"/>
.
Helper functions like resolvePath can be used by template instructions in XML template views, e.g. <template:with path="meta>Value" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="target">
.
Since 1.31.0, you DO NOT need to jQuery.sap.require this module before use.
Since: 1.27.0.
template:with
instruction that depending on how it is called goes to the entity set with the given name or to the one determined by the last navigation property.template:with
instruction that goes to the entity type with the qualified name which oContext
points at.template:with
instruction that goes to the function import with the name which oContext
points at.template:with
instruction that resolves a dynamic "14.5.2 Expression edm:AnnotationPath", "14.5.11 Expression edm:NavigationPropertyPath", "14.5.12 Expression edm:Path" or "14.5.13 Expression edm:PropertyPath".boolean
,number
,undefined
: The part is a constant value.string
: The part is a data binding expression with complex binding syntax (for example, as created by format) and is parsed accordingly to create either a constant value or a binding info object. Proper backslash escaping must be used for constant values with curly braces.object
: The part is a binding info object if it has a "path" or "parts" property, otherwise it is a constant value.
If all parts are constant values, the resulting property setting is also a constant value computed by applying the root formatter function to the constant parts once. If at least one part is a binding info object, the resulting property setting is also a binding info object and the root formatter function will be applied again and again to the current values of all parts, no matter whether constant or variable.
Note: The root formatter function should not rely on its this
value because it depends on how the function is called.
Note: A single data binding expression can be given directly to applySettings, no need to call this function first.
Example:
function myRootFormatter(oValue1, oValue2, sFullName, sGreeting, iAnswer) { return ...; //TODO compute something useful from the given values } oSupplierContext = oMetaModel.getMetaContext("/ProductSet('HT-1021')/ToSupplier"); oValueContext = oMetaModel.createBindingContext("com.sap.vocabularies.UI.v1.DataPoint/Value", oSupplierContext); vPropertySetting = sap.ui.model.odata.AnnotationHelper.createPropertySetting([ sap.ui.model.odata.AnnotationHelper.format(oValueContext), "{path : 'meta>Value', formatter : 'sap.ui.model.odata.AnnotationHelper.simplePath'}", "{:= 'Mr. ' + ${/FirstName} + ' ' + ${/LastName}}", "hello, world!", 42 ], myRootFormatter); oControl.applySettings({"someProperty" : vPropertySetting});
{any[]} | vParts | array of parts |
{function} | fnRootFormatter? | root formatter function; default: Array.prototype.join(., " ") in case of multiple parts, just like getExternalValue |
- Since:
- 1.31.0
{Error} | if some part has an unsupported type or refers to a function name which is not found |
{any|object} | constant value or binding info object for a property as expected by applySettings |
- the "14.4 Constant Expressions" for "edm:Bool", "edm:Date", "edm:DateTimeOffset", "edm:Decimal", "edm:Float", "edm:Guid", "edm:Int", "edm:TimeOfDay".
- the constant "14.4.11 Expression edm:String": This is turned into a fixed text (e.g.
"Width"
) or into a data binding expression (e.g."{/##/dataServices/schema/0/entityType/1/com.sap.vocabularies.UI.v1.FieldGroup#Dimensions/Data/0/Label/String}"
). Data binding expressions are used in case XML template processing has been started with the settingbindTexts : true
. The purpose is to reference translatable texts from OData V4 annotations, especially for XML template processing at design time. Since 1.31.0, string constants that contain a simple binding"{@i18n>...}"
to the hard-coded model name "@i18n" with arbitrary path are not turned into a fixed text, but kept as a data binding expression; this allows local annotation files to refer to a resource bundle for internationalization. - the dynamic "14.5.1 Comparison and Logical Operators": These are turned into expression bindings to perform the operations at run-time.
- the dynamic "14.5.3 Expression edm:Apply":
- "14.5.3.1.1 Function odata.concat": This is turned into a data binding expression relative to an entity.
- "14.5.3.1.2 Function odata.fillUriTemplate": This is turned into an expression binding to fill the template at run-time.
- "14.5.3.1.3 Function odata.uriEncode": This is turned into an expression binding to encode the parameter at run-time.
- Apply functions may be nested arbitrarily.
- the dynamic "14.5.6 Expression edm:If": This is turned into an expression binding to be evaluated at run-time. The expression is a conditional expression like
"{=condition ? expression1 : expression2}"
. - the dynamic "14.5.10 Expression edm:Null": This is turned into a
null
value. Inodata.concat
it is ignored. - the dynamic "14.5.12 Expression edm:Path" and "14.5.13 Expression edm:PropertyPath": This is turned into a data binding relative to an entity, including type information and constraints as available from meta data, e.g.
"{path : 'Name', type : 'sap.ui.model.odata.type.String', constraints : {'maxLength':'255'}}"
. Depending on the used type, some additional constraints of this type are set:- Edm.DateTime: The "displayFormat" constraint is set to the value of the "sap:display-format" annotation of the referenced property.
- Edm.Decimal: The "precision" and "scale" constraints are set to the values of the corresponding attributes of the referenced property.
- Edm.String: The "maxLength" constraint is set to the value of the corresponding attribute of the referenced property and the "isDigitSequence" constraint is set to the value of the "com.sap.vocabularies.Common.v1.IsDigitSequence" annotation of the referenced property.
Example:
<Text text="{path: 'meta>Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
{sap.ui.core.util.XMLPreprocessor.IContext|sap.ui.model.Context} | oInterface | the callback interface related to the current formatter call |
{any} | vRawValue? | the raw value from the meta model, which is embedded within an entity set or entity type:
|
{string} | the resulting string value to write into the processed XML |
- "14.5.2 Expression edm:AnnotationPath"
- "14.5.11 Expression edm:NavigationPropertyPath"
- "14.5.12 Expression edm:Path"
- "14.5.13 Expression edm:PropertyPath"
Examples:
<template:if test="{path: 'facet>Target', formatter: 'sap.ui.model.odata.AnnotationHelper.getNavigationPath'}"> <form:SimpleForm binding="{path: 'facet>Target', formatter: 'sap.ui.model.odata.AnnotationHelper.getNavigationPath'}" /> </template:if>
{sap.ui.core.util.XMLPreprocessor.IContext|sap.ui.model.Context} | oInterface | the callback interface related to the current formatter call |
{any} | vRawValue? | the raw value from the meta model, e.g. {AnnotationPath : "ToSupplier/@com.sap.vocabularies.Communication.v1.Address"} or {AnnotationPath : "@com.sap.vocabularies.UI.v1.FieldGroup#Dimensions"} ; embedded within an entity set or entity type;
|
{string} | the resulting string value to write into the processed XML, e.g. "{ToSupplier}" or "{}" (in case no navigation is needed); returns "" in case the navigation path cannot be determined (this is treated as falsy in template:if statements!) |
template:with
instruction that depending on how it is called goes to the entity set with the given name or to the one determined by the last navigation property. Supports the following dynamic expressions: - "14.5.2 Expression edm:AnnotationPath"
- "14.5.11 Expression edm:NavigationPropertyPath"
- "14.5.12 Expression edm:Path"
- "14.5.13 Expression edm:PropertyPath"
Example:
<template:with path="facet>Target" helper="sap.ui.model.odata.AnnotationHelper.gotoEntitySet" var="entitySet"/> <template:with path="associationSetEnd>entitySet" helper="sap.ui.model.odata.AnnotationHelper.gotoEntitySet" var="entitySet"/>
{sap.ui.model.Context} | oContext | a context which must point to a simple string or to an annotation (or annotation property) of type Edm.AnnotationPath , Edm.NaviagtionPropertyPath , Edm.Path , or Edm.PropertyPath embedded within an entity set or entity type; the context's model must be an sap.ui.model.odata.ODataMetaModel |
{string} | the path to the entity set, or undefined if no such set is found |
template:with
instruction that goes to the entity type with the qualified name which oContext
points at. Example: Assume that "entitySet" refers to an entity set within an OData meta model; the helper function is then called on the "entityType" property of that entity set (which holds the qualified name of the entity type) and in turn the path of that entity type is assigned to the variable "entityType".
<template:with path="entitySet>entityType" helper="sap.ui.model.odata.AnnotationHelper.gotoEntityType" var="entityType">
{sap.ui.model.Context} | oContext | a context which must point to the qualified name of an entity type; the context's model must be an sap.ui.model.odata.ODataMetaModel |
{string} | the path to the entity type with the given qualified name, or undefined if no such type is found |
template:with
instruction that goes to the function import with the name which oContext
points at. Example: Assume that "dataField" refers to a DataFieldForAction within an OData meta model; the helper function is then called on the "Action" property of that data field (which holds an object with the qualified name of the function import in the String
property) and in turn the path of that function import is assigned to the variable "function".
<template:with path="dataField>Action" helper="sap.ui.model.odata.AnnotationHelper.gotoFunctionImport" var="function">
{sap.ui.model.Context} | oContext | a context which must point to an object with a String property, which holds the qualified name of the function import; the context's model must be an sap.ui.model.odata.ODataMetaModel |
- Since:
- 1.29.1
{string} | the path to the function import with the given qualified name, or undefined if no function import is found |
- "14.5.2 Expression edm:AnnotationPath"
- "14.5.11 Expression edm:NavigationPropertyPath"
- "14.5.12 Expression edm:Path"
- "14.5.13 Expression edm:PropertyPath"
Examples:
<template:if test="{path: 'facet>Target', formatter: 'sap.ui.model.odata.AnnotationHelper.isMultiple'}">
{sap.ui.core.util.XMLPreprocessor.IContext|sap.ui.model.Context} | oInterface | the callback interface related to the current formatter call |
{any} | vRawValue? | the raw value from the meta model, e.g. {AnnotationPath : "ToSupplier/@com.sap.vocabularies.Communication.v1.Address"} or {AnnotationPath : "@com.sap.vocabularies.UI.v1.FieldGroup#Dimensions"} ; embedded within an entity set or entity type;
|
{Error} | if the navigation path has an association end with multiplicity "*" which is not the last one |
{string} | "true" if the navigation path ends with an association end with multiplicity "*", "" in case the navigation path cannot be determined, "false" otherwise (the latter are both treated as falsy in template:if statements!) |
template:with
instruction that resolves a dynamic "14.5.2 Expression edm:AnnotationPath", "14.5.11 Expression edm:NavigationPropertyPath", "14.5.12 Expression edm:Path" or "14.5.13 Expression edm:PropertyPath". Currently supports navigation properties and term casts. Example:
<template:with path="meta>Value" helper="sap.ui.model.odata.AnnotationHelper.resolvePath" var="target">
{sap.ui.model.Context} | oContext | a context which must point to an annotation or annotation property of type Edm.AnnotationPath , Edm.NavigationPropertyPath , Edm.Path or Edm.PropertyPath , embedded within an entity set or entity type; the context's model must be an sap.ui.model.odata.ODataMetaModel |
{string} | the path to the target, or undefined in case the path cannot be resolved |
In contrast to format
, "14.5.12 Expression edm:Path" or "14.5.13 Expression edm:PropertyPath" is turned into a simple binding path without type or constraint information. In certain cases, a complex binding is required to allow for proper escaping of the path.
Example:
<sfi:SmartField value="{path: 'meta>Value', formatter: 'sap.ui.model.odata.AnnotationHelper.simplePath'}"/>
{sap.ui.core.util.XMLPreprocessor.IContext|sap.ui.model.Context} | oInterface | the callback interface related to the current formatter call |
{any} | vRawValue? | the raw value from the meta model, which is embedded within an entity set or entity type:
|
{string} | the resulting string value to write into the processed XML |