Hello World – first SAPUI5 Application
After learning about MVC Architecture, you are ready to design first SAPUI5 Application – Hello World. Note that each SAPUI5 project contains at least each of an index, view, controller and Component files arranged in the proper folder structure. Follow tutorial MVC Architecture to maintain required Project Structure.
SAPUI5 libraries primarily divided into two categories:
- sap.m (for Mobile and Desktop Applications)
- sap.ui.commons (for Desktop Applications only), now deprecated (no more used)
Index.html file is the welcome page for your project. It will be loaded before all files. Let’s have a walkthrough to default code, so generated–
Following are key points to be noted –
- ‘data-sap-ui-libs’ loads ‘sap.m’ library which is required for the application.
- ‘sap-ui-core.js’ is the most important core library which will be always used in our applications.
- sap_bluecrystal is the default background theme, which is most widely used. You will get look & feel of it in output.
- Each application is assigned with some namespace (or alias). Here it is ‘ns’ (you can take anything). Namespace represents your project and it is useful in case of Multi-projects environment. All files present in ‘WebContent’ can be referenced using a namespace, for example, to refer controller you will use the path as ‘ns.controller.Main’.
- Index file routes towards Component file, which contains metadata information of the application.
Let’s have a look on the content of Compoenent.js
This file encapsulates your whole project as a Component, which also contains metadata of project.
Note that metadata is maintained in JSON Format. Initialization of Component remains same in all applications.
This is the default code generated for View. In upcoming tutorials, we will add our code to this. Please note that it is in XML.
No need to make changes in default code unless Controller name is incorrect. To mention controller path, use a namespace, as discussed above.
Like Component.js, we have ‘sap.ui. define’ having library for controller – ‘sap/ui/core/mvc/Controller’. In next line, ‘Controller’ represents this library, which is extended in return statement.
Init function is mandatory in a Controller. If nothing to be performed by this function, keep it blank. The purpose of this function is discussed in next tutorial.
To Check the output of this project –
Right Click on Project – > Run As- Web App Preview.
A new tab will open within eclipse having address as: http://localhost:<port>/App/index.html
To see this in a Browser, Copy and paste this URL in Browser. This is the output of your Hello World project.
You have achieved the first milestone in this SAPUI5 Learning. Congratulations!
You can get Source Code of this project from GitHub – https://github.com/iankitgarg/SAPUI5
Drop your queries below and share this Tutorial with your colleagues using following Social Platforms and Stay tuned for next tutorials.