Show TOC

Replacement of BindingsLocate this document in the navigation structure

For attributes, you do not need templating instructions but use SAPUI5 binding expressions instead as in the below code snippet. Each XML attribute is checked to see if its value represents a valid SAPUI5 binding which refers to currently available model (= <variable>) names only. If so, the binding is evaluated and the result is written back into that XML attribute.

Note the usage of the method sap.ui.model.odata.AnnotationHelper.format as a formatter which properly interprets OData Version 4.0 annotations from the ODataMetaModel. You can use this same formatter for labels and values. For more information, see SAP Annotations for OData Version 2.0.

Normally, one would not need any formatter for labels and could instead point to 'badge>MainInfo/Label/String', but this does not take care of escaping and works only for string constants. The sap.ui.model.odata.AnnotationHelper.format is also able to insert references to translatable texts in case the preprocessor has been called with bindTexts : true, which is important for design-time templating.


Template with Some Binding
Sample Code
<Label text="{path: 'badge>MainInfo/Label', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}"/>
<Text text="{path: 'field>Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />

At the time the binding is resolved, field>Value will refer to meta>/dataServices/schema/0/entityType/0/ The resulting XML DOM is shown below. Any references to the meta model are gone. Also the type information, including constraints, has been inserted into the binding.


Result after Replacement of Binding
Sample Code
<Label text="Phone"/>
<Text text="{path : 'PhoneNumber', type : 'sap.ui.model.odata.type.String', constraints : {'maxLength':'30'}}" />

Custom Formatter Functions

You can also write your own custom formatter functions. For details about how to access the model and path related to the current formatter call, see sap.ui.core.util.XMLPreprocessor.IContext in the API reference.