Skip to Content
0

Help defining a controller in Component.js

Nov 27, 2017 at 09:28 AM

39

avatar image
Former Member

So I am following this tutorial, where all has gone well until I hit step 19.

I am following it along from within HANA Studio not the Web IDE and I have made one change in declaring the root directory.

The tutorial suggested (in step 4):
data-sap-ui-resourceroots='{ "sap.ui.demo.wt": "./" }'

I declared it as:
data-sap-ui-resourceroots='{"xsapp": "/xxxx/0RPO/XSAPPS/CD126_test/"}'

So now we have that out of the way, I believe my problem relates to how I am defining the Dialog within Controller.js. In the tutorial it starts like this:

sap.ui.define([
	"sap/ui/core/UIComponent",
	"sap/ui/model/json/JSONModel",
	"sap/ui/demo/wt/controller/HelloDialog"

], function (UIComponent, JSONModel, HelloDialog) {......}

My guess, is that my problem comes from line 4 above but I cannot workout what the full path refers to. I mean I know what the target is but this does not resemble my directory path which would be /xxxx/0RPO/XSAPPS/CD126_test/controller/HelloDialog.controller.js. I have also tried defining it with the full URI which looks something like:http://server:port/xxxx/0RPO/XSAPPS/CD126_test/controller/HelloDialog.controller.js and like: xsapp(which refers to the root directory)/controller/HelloDialog.

So what am I doing wrong.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Irfan Gokak Nov 27, 2017 at 02:51 PM
0

Hi,

This parameter defines root path of your application. Take a look.

data-sap-ui-resourceroots='{ "sap.ui.demo.wt": "./" }'

Here your project path starts from sap.ui.demo.wt and to access particular controller you have to define it as

sap.ui.define(["sap/ui/demo/wt/controller/HelloDialog"

And in your case you have specified it wrong. It’s exact syntax is.

data-sap-ui-resourceroots='{ "<any path name>": "./" }'

“./“ is your root folder of your app.

Hope it’s clear.

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

So I got that bit and I altered it quite successfully. What you are referring to is the resource root property from the bootstrapping. For me the following "./" did not work (however I have changed the full path back to ./, which has had no effective).

data-sap-ui-resourceroots='{ "sap.ui.demo.wt": "./" }'

Instead I had to specify a more complete path like this:

data-sap-ui-resourceroots='{"xsapp": "/xxxx/0RPO/XSAPPS/CD126_test/"}'

So you can see I amended this and every reference to "sap.ui.demo.wt" throughout my app was changed to "xsapp". This does exactly as desired, it was implemented in step 4 and all was good to step 19.

The confusion comes in when defining a controller within Component.js (step 19) this almost appears to refer to the original root declaration but it does not work if I go down this root.

The tutorial says to do this (specifically to add the the following line to the existing: "sap/ui/demo/wt/controller/HelloDialog"

sap.ui.define([
	"sap/ui/core/UIComponent",
	"sap/ui/model/json/JSONModel",
	"sap/ui/demo/wt/controller/HelloDialog"

], function (UIComponent, JSONModel, HelloDialog) {......

However based on my amendment to the bootstrap property above, I did this, changing the above, to: "xsapp/controller/HelloDialog"

sap.ui.define([
	"sap/ui/core/UIComponent",
	"sap/ui/model/json/JSONModel",
	"xsapp/controller/HelloDialog"

], function (UIComponent, JSONModel, HelloDialog) {......

I tried both methods and a number of other variants including replacing the / (slashes) with . (dots).

I guess the question is, how do I properly define local controllers if not like above?

0

Hi Craig,

Sorry, but i don't know how does this path go on Hana Studio. But that's what my understanding is as i explained.

0
Former Member

What you explained was correct, it deals with declaring the root directory in the index.html. Which as I said, I have this sorted, I have made amendments to it but it still works as expected.

My concern relates to declaring my controllers from the Component.js

Thanks though for your input.

1