cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ControllerExtension inside Controller Extension

clementroyer11
Explorer
0 Likes
2,042

Hi everyone,
I hope everyone is doing great !

I have recently discovered ControllerExtensions and I found them really useful.
It's a clean way of separating code and make it reusable. So I'm currently trying to implement this into my code. Most of my extensions are for select dialog.

But I'm facing an issue with the implementation.
On one dialog I need to call another dialog, which is also a ControllerExtension, so I'm trying to add a ControllerExtension to my current ControllerExtension ..

Does anyone know if this is something possible ? Or did I misunderstand the principle of ControllerExtensions ?

Thanks 🙂

Have a great day !

Accepted Solutions (0)

Answers (1)

Answers (1)

FlorianVogt
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Clement,

ControllerExtensions are powerful and a fascinating feature of UI5. Currently, we have only https://ui5.sap.com/#/topic/21515f09c0324218bb705b27407f5d61 for documentation purposes but there is already a huge documentation update under construction.

Coming to your question, yes using an existing extension is possible. Just require it like your are used to with other modules.

FlorianVogt
Product and Topic Expert
Product and Topic Expert

This sample is quite helpful: https://plnkr.co/edit/xnVMDtx8f2IgI91A?preview
But it has no nested extensions. I'll update the post here as soon I found a sample for you.

clementroyer11
Explorer
0 Likes
Hi Florian !
I'm very happy to hear that a huge documentation will be posted one day.

Thank you for your answer, unfortunately this doesn't work this easily for me.
Here is my code: 

Use with controller:

sap.ui.define([
  "sap/ui/core/mvc/Controller",
  "xx/xx/xxx/controller/extension/articleHelper",
  "xx/xx/xxx/controller/extension/locationHelper",
  "xx/xx/xxx/controller/extension/mouvementDialog"
],function (Controller, helperHandler, articleHelper, locationHelper, mouvementDialog) {
	"use strict";

	return Controller.extend("xx.xx.xxx.controller.asset", {
		formatter: formatter,
		articleHelper: articleHelper,
		locationHelper: locationHelper, //
		mouvementDialog: mouvementDialog,

                onInit: function () { console.log("assetController"); }
        });
});

Result : (log)

Use within an other ControllerExtension:

(Remove all call to locationHelper inside fist controller)

mouvementDialog.js

sap.ui.define([
	"sap/ui/core/mvc/ControllerExtension"
	"xx/xx/xxx/controller/extension/locationHelper"
], function (ControllerExtension, locationHelper) {
	"use strict";

	return ControllerExtension.extend("xx.xx.xxx.controller.extension.mouvementDialog", {
		locationHelper: locationHelper,
	
		override: {
			onInit: function () { console.log("Initize mouvementDialog."); }
		},

        });
 ));

Result :

Maybe I'm missing something ?

clementroyer11
Explorer

Also I found this answer that was VERY helpful to implement ControllerExtension : stackoverflow