SAPUI5 MVC Walkthrough

Project Structure

SAPUI5のMVCのプロジェクトのファイル構成

Index.html

Let's have a look at sap.ui.getCore().attachInit(function ()

attachInit(fnFunction)

Registers a given function that is executed after the framework has been initialized.

The given function will either be called as soon as the framework has been initialized or, if it has been initialized already, it will be called immediately.

Run the function after frame initiation. Inside the function. It create a new component runtime by component ID. At the last. Place the content from component to the content of SAPUI5 framework.

#TK Shell

Component

Component is simple because most of settings have been moved into metadata. What this component do is initiation and get the router.

manifest.json

manifest.json defined controls's property and the routing rule. Component.js get the routing data from this file.

i18n.property

i18n.property defined the global Constant variable.

View

app.view.xml

Note the end of the file is xml. Which mean it's view type.

You must be curious that how app view link to other view? Let's look

In the manifest.json file. because of the definition of rootview and routing. SAPUI5 would handle the relationship between app and master/detail view.

If you don't have manifest.json and component.js. you should do like this in app.view.xml:

Master.view.xml

Basically there are some predefined components in the master view. The point you should notice :

  • use controllerName="sapui5.demo.mvcapp.controller.Master" to bind controller

  • use {Name} to bind the data

  • use navButtonPress="onNavBack" / press="onListPress" bind controller function

Detail.view.xml

It's same with Master so let's skip it.

Controller

BaseController.js

User getRouter, getModel, setModel, getResourceBundle to initiate router, model, resource from i18n.

Define function myNavBack for detail controller.

Master.controller.js

In the master controller. we defined 2 even handler.

  1. onListPress: call internal method _showObject to route to detail page.

Detail.controller.js

Last updated

Was this helpful?