Reputation: 416
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.
Upvotes: 2
Views: 11914
Reputation: 197
By calling method sap.ui.controller("MyForm", {})
,
the "MyForm" controller is not defined and is never available in execution scope.
Where
sap.ui.core.mvc.Controller.extend("MyForm", {})
defines function and referred by "MyForm", and has extend defined on it.
Upvotes: 0
Reputation: 483
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
Upvotes: 4