SAPUI5 - extend a sap.ui.controller implementation
10,911
Solution 1
it works like this:
code of the base controller:
sap.ui.core.mvc.Controller.extend("MyForm", {
showMyName: function() {
alert("MyForm.showMyName");
},
//Further functions ....
});
code of the MyNewForm controller using the MyForm as base:
//require the base first
jQuery.sap.require("MyForm");
//extent the base
MyNewForm.extend("MyForm", {
onInit : function() {
this.showMyName(); //alerts
}
})
In this demoapp you see it in action: https://sapui5.netweaver.ondemand.com/sdk/test-resources/sap/m/demokit/tdg/index.html?responderOn=true look for util/Controller.js as base class and for view/Master.Controller.js as usage of the class.
Best Regards
Solution 2
I think it should be:
MyForm.extend("MyNewForm", {
Author by
mjd
Updated on July 23, 2022Comments
-
mjd almost 2 years
I would like to implement a new controller that would redefine some methods from an existing controller.
Let say I have:
MyForm.controller.js
sap.ui.controller("MyForm", { showMyName: function() { alert("MyForm.showMyName"); }, onSearch: function(oEvent) { // Do something... }, });
I would like a new MyNewForm controller that would override the method showMyName but would inherit the onSearch method. Any ideas how this could achieved?
Thanks in advance.
-
mjd over 9 yearsThis works great, Thanks. I had already checked this example but because something I've missed the code didn't work. So, just some pointers for future reference: 1) The base controller class doesn't end with the sufix .controller.js, it is just a regular .js file; 2) The base controller cannot be used directly as a controller class for a view.
-
Satish N Ramteare over 7 yearsThis is really helpful.