on 10-22-2015 8:27 AM
Hi all, I need to attach a controller to a block. I need an html control element within the block, and I need to reference it from a controller (this.getView().byId("main").setContent(content) ) .
I created the block folder in the source control of the application. I added a BlockName.js which extends BlockBase. I added a BlockName.view.xml view too. But now, I need to attach a controller to this view.
The view shown well, but when I add this line in the BlockName.view.xml for add the associated controller:
controllerName="sap.ui.demo.myFiori.block.GoalsBlock"
It gives an error in Chrome and the console displays the following error:
Uncaught Error: Controller sap.ui.demo.myFiori.block.GoalsBlock couldn't be instantiated
block Folder:
BlockName.js
jQuery.sap.declare("sap.ui.demo.myFiori.block.BlockName");
jQuery.sap.require("sap.uxap.BlockBase");
sap.uxap.BlockBase.extend("sap.ui.demo.myFiori.block.BlockName", {
metadata: {
views: {
Collapsed: {
viewName: "sap.ui.demo.myFiori.block.BlockName",
type: "XML"
},
Expanded: {
viewName: "sap.ui.demo.myFiori.block.BlockName",
type: "XML"
}
}
}
});
BlockName.view.xml
<core:View
controllerName="sap.ui.demo.myFiori.block.BlockNameController"
xmlns:core="sap.ui.core"
xmlns="sap.m">
<Label text="Test"/>
<core:HTML id="main">
</core:HTML>
</core:View>
BlockNameController.controller.js
............................
Thanks
Hi Juan Carlos Orta,
you need to rename your block controller from GoalsBlock to GoalsBlockController, afterwards it should work.
Of course you need to adjust the controller name also in the controller and in the view.
Cheers,
Dominik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got what I wanted with the rendered and onAfterRendering methods in BlockName.js.
But anyway, I still like to know how to add the associated controller.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Juan Carlos Orta,
Hope this link will help you
Is it possible to associate fragment directly to Block instead of view?
Thanks and Regards,
Puneet Jain
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.