docs

Annotation Helper

A collection of methods which help to consume OData Version 4.0 annotations in XML template views.

The AnnotationHelper connects all the pieces related to XML templating: It knows the OData meta model and its structure as well as the OData v4 annotations. The AnnotationHelper offers formatter functions and helper functions. You can call these methods directly from the JavaScript code without XML runtime templating. You need to require sap/ui/model/odata/AnnotationHelper before use. Make sure to require the sap/ui/model/odata/ODataExpressionAddons module in advance or, if you need to minimize the loading of modules (for example, for performance reasons), you can also require the corresponding modules individually as indicated below.

Tip:

You can see more information on the expressions, constants and functions used by the AnnotationHelper, in the respective chapters of the specification OData Version 4.0 Specification: Part 3: Common Schema Definition Language .


Formatter Functions

The formatter functions can be used in binding expressions and <template:if> instructions for test conditions. The following formatter functions exist:

The formatter functions can also be called directly from JavaScript. The following code snippet shows an example for the use of a formatter function outside templating:

var oModel = this.getModel(),
    sPath = "##com.sap.vocabularies.UI.v1.HeaderInfo/Description/Label",
    oContext = oModel.getContext(oModel.resolve(sPath, this.getBindingContext())),
    oLabel = new sap.m.Label({text: AnnotationHelper.format(oContext)}));
...

The formatter functions are called with a context object as first parameter. The second parameter (vRawValue) is optional. If the value is not provided, it is calculated in the formatter function. If the application has already calculated the value, it passes the raw value as second parameter, thus avoiding unnecessary further calculations of the raw value.


Helper Functions

The following helper functions can be used with <template:with>:

Related Information

sap.ui.model.odata.AnnotationHelper

OData Version 4.0