You can migrate the deprecated registerControllerExtensions API.
As of SAPUI5 1.120 release, the registerControllerExtensionsAPI is getting deprecated. It is planned to be removed from the SAPUI5 version 2.0.
Following are the requirements that describe why the API is getting deprecated:
-
Now, SAPUI5 provides capabilities to register multiple controller extensions for a single floorplan (one controller extension per view) directly through the manifest. In this case, the
registerControllerExtensionsAPI is not required anymore. -
The
registerControllerExtensionsAPI internally uses thesap.ui.controllerAPI.
The current setup has the following three controller extension files for the object page:
-
DetailsExtension.controller.jsThe parent controller that invokes extension API
registerControllerExtensionsand registers the remaining two child controllers. -
SalesOrderExtension.controller.jsOne of the child controllers that is responsible for the
Sales Orderview (bound withC_STTA_SalesOrder_WD_20entity set). -
SalesOrderItemExtension.controller.jsOne of the child controllers that is responsible for the
Sales Order Itemview (bound withC_STTA_SalesOrderItem_WD_20entity set).
From SAPUI5 version 2.0, only the two child controller files are going to be required
Step 1: Changes Required in the manifest.json
-
Register all the child controllers under
sap.ui.controllerExtensionssection ofmanifest.json. The registered entry must be in<FLOOR_PLAN_NAME>#<STABLE_ID_OF_VIEW>format. For example, theSalesOrderExtension.controller.jsis to be registered as the following:manifest.json"sap.ui.controllerExtensions": { ... "sap.suite.ui.generic.template.ObjectPage.view.Details#STTASOWD20::sap.suite.ui.generic.template.ObjectPage.view.Details::C_STTA_SalesOrder_WD_20": { "controllerName": "STTASOWD20.ext.controller.SalesOrderExtension", "sap.ui.generic.app": { "C_STTA_SalesOrder_WD_20": { "EntitySet": "C_STTA_SalesOrder_WD_20", "Header": { "Actions": { ... } }, "Sections": { "Actions": { ... } } } } } } -
Copy the content (such as, header actions, section actions) of parent controller extension to the respective child controller extensions.
-
Remove the entry of parent controller extension from
sap.ui.controllerExtensionssection ofmanifest.json.
Step 2: Changes Required in the Controller Extensions
-
Remove the parent controller extension file.
-
All the child controller extension files must extend the
sap.ui.core.mvc.ControllerExtensionclass.sap.ui.define([ "sap/ui/core/mvc/ControllerExtension" ], function (ControllerExtension) { 'use strict'; return ControllerExtension.extend("STTASOWD20.ext.controller.SalesOrderExtension", { override: { // Overridden methods }, // Custom methods }); }); -
All the overridden methods must be kept under the
overridesection of the controller extension class. It includes the following:-
All the methods provided by SAPUI5 (for e.g: onInit)
-
All the methods of
ObjectPage controllerFrameworkExtensions(for e.g:adaptNavigationParameterExtension,beforeSaveExtension)
-
-
All the custom methods are to be added after the
overridesection:sap.ui.define([ "sap/ui/core/mvc/ControllerExtension" ], function (ControllerExtension) { 'use strict'; return ControllerExtension.extend("STTASOWD20.ext.controller.SalesOrderExtension", { override: { onInit: function(){ }, adaptNavigationParameterExtension: function (oSelectionVariant, oObjectInfo) {}, onBeforeRendering: function () {}, beforeDeleteExtension: function () {}, beforeSaveExtension: function () {} }, onObjectPage1CustomAction: function () { }, onSalesOrderInfo: function () {}, onSalesOrderItemInfo: function () {} }); });
Steps 3: Changes Required in Declaring the Press Event Handlers in the Manifest
Earlier, the event handlers for custom actions (that are implemented in controller extensions) were declared in the manifest by the name. In the following example, onObjectPage1CustomAction is the press event handler for the custom action ObjectPageCustomAction.
"sap.ui.generic.app": { "C_STTA_SalesOrder_WD_20": { "EntitySet": "C_STTA_SalesOrder_WD_20", "Header": { "Actions": { "ObjectPageCustomAction": { "id": "ObjectPageCustomAction", "text": "Custom Action 1", "press": "onObjectPage1CustomAction", "determining": true, "applicablePath": "IsActiveEntity" } } } } }
It is now going to be changed to extension.<CONTROLLER_MODULE_NAME>.<METHOD_NAME> format.
"sap.ui.generic.app": { "C_STTA_SalesOrder_WD_20": { "EntitySet": "C_STTA_SalesOrder_WD_20", "Header": { "Actions": { "ObjectPageCustomAction": { "id": "ObjectPageCustomAction", "text": "Custom Action 1", "press": ".extension.STTASOWD20.ext.controller.SalesOrderExtension.onObjectPage1CustomAction", "determining": true, "applicablePath": "IsActiveEntity" } } } } }
Use the same format while referring to the custom methods from view and fragment files.
In the following example, refer to the press handler of the button.
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns="sap.m"> <Button id="previousMemoBtn" text="{i18n>yes}" press=".extension.SSTASOWD20.ext.controller.SalesOrderExtension.onPressPreviousMemo" /> </core:FragmentDefinition>
You can get the instance of extensionAPI using this.getView().getController().extensionAPI. You can find more information in the following sample:
sap.ui.define([ "sap/ui/core/mvc/ControllerExtension" ], function (ControllerExtension) { 'use strict'; return ControllerExtension.extend("STTASOWD20.ext.controller.SalesOrderExtension", { override: { onInit: function () { // Initializing extensionAPI this.extensionAPI = this.getView().getController().extensionAPI; } }, onSalesOrderInfo: function () { // Using extensionAPI var aSelectedContexts = this.extensionAPI.getSelectedContexts("SalesOrderItemsID::responsiveTable"); } }); });