Context interface provided by XML template processing as an additional first argument to any formatter function which opts in to this mechanism. Candidates for such formatter functions are all those used in binding expressions which are evaluated during XML template processing, including those used inside template instructions like <template:if>
. The formatter function needs to be marked with a property requiresIContext = true
to express that it requires this extended signature (compared to ordinary formatter functions). The usual arguments are provided after the first one (currently: the raw value from the model).
This interface provides callback functions to access the model and path which are needed to process OData V4 annotations. It initially offers a subset of methods from sap.ui.model.Context so that formatters might also be called with a context object for convenience, e.g. outside of XML template processing (see below for an exception to this rule).
Example: Suppose you have a formatter function called "foo" like below and it is used within an XML template like <template:if test="{path: '...', formatter: 'foo'}">
. In this case foo
is called with arguments oInterface, vRawValue
such that oInterface.getModel().getObject(oInterface.getPath()) === vRawValue
holds.
window.foo = function (oInterface, vRawValue) {
//TODO ...
};
window.foo.requiresIContext = true;
Composite Binding Examples: Suppose you have the same formatter function and it is used in a composite binding like <Text text="{path: 'Label', formatter: 'foo'}: {path: 'Value', formatter: 'foo'}"/>
. In this case oInterface.getPath()
refers to ".../Label" in the 1st call and ".../Value" in the 2nd call. This means each formatter call knows which part of the composite binding it belongs to and behaves just as if it was an ordinary binding.
Suppose your formatter is not used within a part of the composite binding, but at the root of the composite binding in order to aggregate all parts like <Text text="{parts: [{path: 'Label'}, {path: 'Value'}], formatter: 'foo'}"/>
. In this case oInterface.getPath(0)
refers to ".../Label" and oInterface.getPath(1)
refers to ".../Value". This means, the root formatter can access the ith part of the composite binding at will (since 1.31.0); see also getInterface. The function foo
is called with arguments such that oInterface.getModel(i).getObject(oInterface.getPath(i)) === arguments[i + 1]
holds.
To distinguish those two use cases, just check whether oInterface.getModel() === undefined
, in which case the formatter is called on root level of a composite binding. To find out the number of parts, probe for the smallest non-negative integer where oInterface.getModel(i) === undefined
. This additional functionality is, of course, not available from sap.ui.model.Context, i.e. such formatters MUST be called with an instance of this context interface.
Since: 1.27.1.