Class sap.ui.core.mvc.ControllerModule: sap/ui/core/mvc/Controller
A generic controller implementation for the UI5 Model-View-Controller concept.
Can either be used as a generic controller which is enriched on the fly with methods and properties (see sap.ui.controller) or as a base class for typed controllers.
sClassName
and enriches it with the information contained in oClassInfo
.If there is no Component connected to the view or the view is not connected to the controller, undefined is returned.
{string|object[]} | sName | The name of the controller to instantiate. If a controller is defined as real sub-class, the "arguments" of the sub-class constructor should be given instead. |
sClassName
and enriches it with the information contained in oClassInfo
. oClassInfo
might contain the same kind of information as described in sap.ui.base.EventProvider.extend.
{string} | sClassName | Name of the class being created |
{object} | oClassInfo? | Object literal with information about the class |
{function} | FNMetaImpl? | Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata |
{function} | Created class / constructor function |
{sap.ui.base.Metadata} | Metadata object describing this class |
The extension provider module provides the getControllerExtensions
function which returns either directly an array of objects or a Promise that returns an array of objects when it resolves. These objects are object literals defining the methods and properties of the controller in a similar way as sap.ui.controller.
Example for a callback module definition (sync):
sap.ui.define("my/custom/sync/ExtensionProvider", ['jquery.sap.global'], function(jQuery) { var ExtensionProvider = function() {}; ExtensionProvider.prototype.getControllerExtensions = function(sControllerName, sComponentId, bAsync) { if (!bAsync && sControllerName == "my.own.Controller") { // IMPORTANT: only return extensions for a specific controller return [{ onInit: function() { // Do something here... }, onAfterRendering: function() { // Do something here... }, onButtonClick: function(oEvent) { // Handle the button click event } } }]; }; return ExtensionProvider; }, true);
Example for a callback module definition (async):
sap.ui.define("my/custom/async/ExtensionProvider", ['jquery.sap.global'], function(jQuery) { var ExtensionProvider = function() {}; ExtensionProvider.prototype.getControllerExtensions = function(sControllerName, sComponentId, bAsync) { if (bAsync && sControllerName == "my.own.Controller") { // IMPORTANT: // only return a Promise for a specific controller since it // requires the View/Controller and its parents to run in async // mode! return new Promise(function(fnResolve, fnReject) { fnResolve([{ onInit: function() { // Do something here... }, onAfterRendering: function() { // Do something here... }, onButtonClick: function(oEvent) { // Handle the button click event } }]); } }; }; return ExtensionProvider; }, true);
The lifecycle functions onInit
, onExit
, onBeforeRendering
and onAfterRendering
are added before or after the lifecycle functions of the original controller. The event handler functions, such as onButtonClick
, are replacing the original controller's function.
When using an async extension provider you need to ensure that the view is loaded in async mode.
In both cases, return undefined
if no controller extension shall be applied.
{string} | sExtensionProvider | the module name of the extension provider |
- Since:
- 1.34.0
sap.ui.controller for an overview of the available functions for controllers |
Views automatically prepend their own ID as a prefix to created Elements to make the IDs unique even in the case of multiple view instances. This method helps to find an element by its local ID only.
If no view is connected or if the view doesn't contain an element with the given local ID, undefined is returned.
{string} | sId | View-local ID |
{sap.ui.core.Element} | Element by its (view local) ID |
If no view is connected, undefined is returned.
{string} | sId | View-local ID |
{string} | Prefixed ID |
If there is no Component connected to the view or the view is not connected to the controller, undefined is returned.
- Since:
- 1.23.0
{sap.ui.core.Component} | Component instance |
{sap.ui.core.mvc.View} | View connected to this controller. |
sap.ui.core.Control.prototype.onAfterRendering |
sap.ui.core.Control.prototype.onBeforeRendering |