The API consists of several elements that are described in the sections that follow.
In extension coding, you can use the standard SAPUI5 programming API. However, this should be handled with care.
After you have defined a view extension, you can access and modify the properties of all UI elements defined within these extensions (for example, change the visibility programmatically). However, you cannot access any UI elements that are not defined within your view extensions.
Several models (instances of sap.ui.model.Model) are attached to the smart template artifacts.
The most prominent is the default model, which is in fact the OData model specified in the manifest.json file. You can use this model for data-binding in your own view extensions.
Accessing the model programmatically (through the standard SAPUI5 API methods) should be done with care, since side effects may interfere with the smart template coding that also uses this model.
This applies in particular to function imports. Therefore, use method invokeActions of the extension API (see below) to call function imports.
Each view has its own model attached that has the name ui. This model can be used in view and controller extensions for read purposes.
Note that it is also possible to register changes to these properties. However, the logic at which point in time these properties are set and reset can still be changed.
There is an additional model that is attached to each view which contains properties used for internal purposes within the smart template.
You may want to define your own JSON model and attach it to UI elements. You can do this easily if the model is attached to a UI element that only exists within the scope of an extension. However, models that are attached to a higher level (for example, to the whole view) should only be used if absolutely necessary.
In this case, you should use a name containing your own namespace to clearly separate this model from models defined by other parts of the framework.
When coding the implementation of an extension hook or an event handler used in a view extension, you can use the public methods of sap.ui.core.mvc.Controller. For important information about using standard SAPUI5 programming APIs, see the relevant section above.
In addition, you may want to access a service provided by the smart template framework. From the controller, you can access these services through <YourController>.extensionAPI.
Template |
Instance |
---|---|
List Report |
sap.suite.ui.generic.template.ListReport.extensionAPI.ExtensionAPI |
Object Page |
sap.suite.ui.generic.template.ObjectPage.extensionAPI.ExtensionAPI |
For more information, see the API Reference for sap.suite.ui.generic.template.ListReport.extensionAPI.ExtensionAPI and for sap.suite.ui.generic.template.ObjectPage.extensionAPI.ExtensionAPI in the Demo Kit.
Any other methods or properties of the controller (in particular any components with a name starting with ‘_’) should be considered private and therefore not be used.
/* * Assumed use case: When the price is changed to a critical value (more than 1000), an email should be generated and sent. * This should not happen for changes to the draft but only after activation has been successfully processed in the * back-end system. */ (function() { "use strict"; function onAfterActivate(oEvent) { /* * AfterActivate event is raised at the end of front-end processing for activation. The object handed into the * handler contains a promise that is resolved after a successful response from the back-end system. */ oEvent.activationPromise.then(function(oResponse) { if (oResponse.data.Price > 1000) { sap.m.URLHelper.triggerEmail(null, "critical price change", "changed price of " + oResponse.data.Product_Text + " to " + oResponse.data.Price + " " + oResponse.data.Currency); } }); }