Introducing SAPUI5: Sap Web Ide 2 Bootstrap 3
Introducing SAPUI5: Sap Web Ide 2 Bootstrap 3
Introducing SAPUI5
C O N F I D E N T I AL
Table of Contents
1.1.
1.2. Preview
1/6
Scripts for UI5 Training
UI5 Scripts for Demo Run
August 27, 2018 – C O N F I D E N T I AL
Explanation Screenshot
https://account.hanatrial.ondem
and.com/cockpit
3. Go to the development
perspective by clicking on the
icon “</>” in the left toolbar. On
the left side you will see a
folder list with your app
projects.
2/6
Scripts for UI5 Training
UI5 Scripts for Demo Run
August 27, 2018 – C O N F I D E N T I AL
Bootstrap
In this step, we will create a very simple web page and load the SAPUI5 library.
If you haven’t done so yet in the preparation week of the course, create a project folder and an HTML page. Add
a new project folder MyApp by right-clicking on the “Local” entry in the source tree it and selecting “New >
Folder”.
Inside this folder create a new folder webapp, which will contain all sources of the app we will create throughout
the first weeks of this course. Now create a new root HTML file called index.html in your app folder with the
contents of the listing above.
3/6
Scripts for UI5 Training
UI5 Scripts for Demo Run
August 27, 2018 – C O N F I D E N T I AL
Save your changes and press the button in the header toolbar. A new tab will open with the preview of
your app. In all the following exercises you can test your code like this.
1.1.2. webapp/index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title> Developing Web Apps with SAPUI5</title>
<script
id="sap-ui-bootstrap"
src="https://sapui5.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">
</script>
<script>
sap.ui.getCore().attachInit(function () {
alert("SAPUI5 is ready");
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
Before we can do anything with SAPUI5, we need to load and initialize it. This process of loading and initializing
SAPUI5 is called bootstrapping. Once this bootstrapping is finished, we simply display an alert.
4/6
Scripts for UI5 Training
UI5 Scripts for Demo Run
August 27, 2018 – C O N F I D E N T I AL
In the code above, we load the SAPUI5 framework from the Content Delivery Network (CDN)
at https://sapui5.hana.ondemand.com/resources/sap-ui-core.js.
Note:
You can use this reference to the latest stable version of SAPUI5 for the exercises or for testing purposes,
but never do this for productive use. In an actual app, when using our content delivery network, you
always have to specify an SAPUI5 version explicitly. Have a look at the documentation for more details.
The URL will then look like this: https://sapui5.hana.ondemand.com/1.34.10/resources/sap-ui-
core.js
5/6
Scripts for UI5 Training
UI5 Scripts for Demo Run
August 27, 2018 – C O N F I D E N T I AL
The src attribute of the first <script> tag tells the browser where to find the SAPUI5 core library – it
initializes the SAPUI5 runtime and loads additional resources, such as the libraries specified in
the data-sap-ui-libs attribute.
The SAPUI5 controls support different themes, we choose sap_bluecrystal as our default theme.
We specify the required UI library sap.m containing the UI controls we need for this tutorial.
To make use of the most recent functionality of SAPUI5 we define the compatibility version as edge.
We configure the process of “bootstrapping” to run asynchronously.
This means that the SAPUI5 resources can be loaded simultaneously in the background for
performance reasons.
When all resources and libraries are loaded, the SAPUI5 runtime fires the global init event to signal that the
library is ready. When loading the libraries asynchronously, you have to listen for this event in order to trigger
your application logic only after the required resources are loaded.
In the example above, we get a reference to the SAPUI5 core by calling sap.ui.getCore() and register an
anonymous callback function for the init event by calling attachInit(…) on the core. In SAPUI5 these kinds
of callback functions are often referred to as event handlers, event listener functions, or simply listeners. The
core is a singleton and can be accessed from anywhere in the code.
Our anonymous callback function is executed when the bootstrap of SAPUI5 is finished and displays a native
JavaScript alert.
6/6