I'm doing the SAPUI5 Walkthrough and stuck at step 4. (Walkthrough Step 4)
I'm working with Eclipse and don't know how to change this code-line so it works for my project and is going to find my view.
data-sap-ui-resourceroots='{
"sap.ui.demo.wt": "./"
}'
I need to know what to insert for "sap.ui.demo.wt" when using an Eclipse project.
Thanks for any hints :)
EDIT:
Now I got a working page with a button which triggers a pop-up.
Folder structure:
SAPUI5_Test
- WebContent
- controller
-> NewView.controller.js
- view
-> NewView.view.xml
- index.html
index.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="UTF-8">
<title>SAPUI5 Walkthrough</title>
<script
id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"SAPUI5_Test": "./"
}'>
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.xmlview({
viewName: "SAPUI5_Test.view.NewView"
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
NewView.view.xml:
<mvc:View
controllerName="SAPUI5_Test.controller.NewView"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Button
text="Say hello"
press="onShowHello"/>
</mvc:View>
NewView.controller.js
sap.ui.controller("SAPUI5_Test.controller.NewView", {
onShowHello : function() {
alert("Hello SAPUI5_Controller");
}
});
So thanks for the help! And maybe this could help someone in the future :)
SAPUI5 is searching for resources like views, controllers or other classes by their full names.
It is assuming that every namespace part is a folder and the class/view name is the filename. If its a view the filename has to be xxx.view.xml. if its a controller the filename has to be xxx.controller.js.
The root folder where it starts its search is by default the folder of the sap-ui-core.js.
You can change the root folder by defining a data-sap-ui-resourceroots mapping. Its a javascript object that maps a namespace to a path (relative to the index.html).
With the following bootstrap tag
company.myProject.view.View1
is searched for at/resources/company/myProject/view/View1.view.xml
:With this bootstrap tag
company.myProject.View1
is searched for at/view/View1.view.xml
:And with this bootstrap tag
company.myProject.View1
is searched for atddd/myProject/view/View1.view.xml
:Edit: Please beware that you have to use
"
inside of the map.'
will not work.Edit: Clarification of folder structure
I would recommend that you put everything in a project namespace. Use this folder structure:
data-sap-ui-resourceroots='{ "myproject": "./" }'
.Controller.extend("myproject.controller.NewView", {...});
orsap.ui.controller("myproject.controller.NewView",{...});
.controllerName="myproject.controller.NewView"
.sap.ui.xmlview({ viewName: "myproject.view.NewView"}).placeAt("content");
.With that you don't have to add a mapping for every subfolder in your project.