SAP UI5 Development Guidelines
SAP UI5 Development Guidelines
Guidelines
DS
SAPUI5 Development
Guidelines
Document Information
Document Identification SAPUI5 Development Guidelines
Client NA
Document Author NA
Document Status NA
Name Organization/Title
<Name> <Organization/Title>
Table of Contents
SAPUI5 for Mobile sap.m SAPUI5 contains a dedicated control library for mobile devices like tablets
and smartphones with the technical name sap.m. Both sap.m and the control libraries for the desktop
are based on the same Runtime which provides a common infrastructure for Data Binding, Model-
View-Controller Concepts, Localization and other topics. In addition, both control sets have a
harmonized API for the common parts.
As SAPUI5 is based on web standards like HTML, CSS and JavaScript you can run the application
on multiple platforms. The SAP Blue Crystal theme is the basis for Fiori applications, supports
desktop browsers, and provides common look and feel across different platforms and browsers.
In this Project, we develop HTML5 mobile applications using SAPUI5 mobile toolkit with bulk of the
code being written in javascript. This document's primary motivation is two- fold: 1) code consistency
and 2) best practices. By maintaining consistency in coding styles and conventions, we can ease the
burden of legacy code maintenance, and mitigate risk of breakage in the future. By adhering to best
practices, we ensure optimized page loading, performance and maintainable code.
2.1 Indentation
For all code languages, we require indentation to be done via soft tabs (using the space
character). HittingTab in your text editor shall be equivalent to four spaces.
2.2 Readability vs Compression
We prefer readability over file-size savings when it comes to maintaining existing files. Plenty of
whitespace is encouraged, along with ASCII art, where appropriate. There is no need for any
developer to purposefully compress HTML or CSS, nor obfuscate JavaScript.
We will use server-side or build processes to automatically minify and gzip all static client-side
files, such as CSS and JavaScript.
2.3 HTML5 Guidelines
Place an html comment on some closing div tags to indicate what element you're closing. It
will help when there is lots of nesting and indentation.
Tables shouldn't be used for page layout.
Use microformats and/or Microdata where appropriate, specifically hCard and adr.
Code does not contain inline JavaScript event listeners
Code does not contain inline style attributes
Code does not contain deprecated elements & attributes
Page begins with a valid DTD (HTML5 doctype)
Code is indented using hard tabs
Tags and attributes are lowercase
Tags are closed and nested properly
Markup is semantic (e.g. class names do not denote presentation, Items in list form are
housed in a UL, OL, or DL)
Tables(using Div) are only used to display tabular data
Element IDs are unique
Code validates against the W3C validator
DOM nesting depth does not exceed 12 levels
Total page weight does not exceed client requirements (e.g. 1000kb)
TItle case is used for headers/titles and forced to all caps using the CSS declaration text-
transform: uppercase;
Where text is included via images, CSS image replacement is used.
Add CSS through external files, minimizing the # of files, if possible. It should always be in
the HEAD of the document.
Use the LINK tag to include, never the @import.Including a stylesheet
Don't include styles inline in the document, either in a style tag or on the elements. It's
harder to track down style rules.
Use normalize.css to make rendering more consistent across browsers.
During a page load, there is typically a lot of script waiting to execute, but you can prioritize it.
This order prioritizes based on user response:
Script that changes the visible nature of the page needs to fire absolutely first. This
includes any font adjustment, box layout, or IE6 pngfixes.
Page content initialization
Page header, topnav and footer initialization
Attaching event handlers
Omniture, Doubleclick, and other 3rd party scripts
In the beginning the browser loads the web applications's index.html which contains itself only
minimal code. The index.html then loads the Application.js which actually launches the application
and instantiates the App View which holds the sap.m.App control that serves as root container for all
UI controls. The application user interface is split into 3 pages: Home, Header Detail, Item Detail.
These pages are represented each by a view containing the sap.m.Page control and a controller
handling the view events. When trigger a navigation to another page an event is send via the
EventBus to the App Controller. There are no direct dependencies between views, and those
EventBus events are only used for navigation and parameter handover between pages. To enable
the back button of Android devices the jQuery.sap.history plugin is used which listens to changes in
the browser history and triggers the App Controller for backward navigation. The InstanceManager
tracks open instances of dialogs and popovers. The App controller checks on backward navigation for
open instances and closes them on demand. There are two data models: The Header model
containing the list of header information. The Item Model contains the item details for a selected
header. In addition there are two models that contain resources used by the application: The Image
Model abstracts from access paths and the i18n Model connects to translated texts.
Application.js
Index.html (Application
Startup)
App View
App Controller
sap.m.App
Header Item
Model Model
Sap.ui.core.EventBus
A control name should start with an upper case letter and use camel case for concatenated
words (example: MatrixLayout).
A control property name should start with a lower case letter and use camel case to for
concatenated words (example: colSpan).
A control event name should start with a lower case letter and use camel case to for
concatenated words (example: press).
A control method should start with a lower case letter and use camel case to for
concatenated words (example: doSomething).
A control aggregation should start with a lower case letter and use camel case to for
concatenated words.
A control association should start with a lower case letter use camel case to for
concatenated words.
For a control, properties, events and relations should have unique names to avoid name
clashes for generated classes.
Parameters of control events should start with a lower case letter.
Tag names should start with a lower case letter, and camel case should be used for
concatenated words. Tag names should match the names of the control except tag names
start in lower case. This establishes a natural relation between the tag and its control
(example: matrixLayout).
Tag attributes should start with lower case letters, and camel case should be used for
concatenated words (example: colSpan).
Tag attributes for event handlers should be named on<event-name>, all in lower case
letters (example: onpress).
Within the sap-ui- namespace the following IDs are currently used:
ID Description
sap-ui-library-* Prefix for UI libraries
script tags
sap-ui-theme-* Prefix for theme
stylesheets link tags
sap-ui-highlightrect ID of the highlight rect for
controls in TestSuite
sap-ui-blindlayer-* ID for BlockLayer
sap-ui-static ID of the static area of
SAPUI5
sap-ui-TraceWindowRoot ID of the
TraceWindowRoot
sap-ui-xmldata ID of the XML Data Island
To avoid collisions, all CSS classes written to the HTML must start with "sap" if developed
inside SAP, and with "sapUi" or "sapM" if developed inside the UI5 development teams.
Outside the respective groups this prefixes should not be used.
CSS classes for a certain control should add the control name or an abbreviation of it to
the above prefix. Controls outside the "commons" library may benefit from adding also the
library name in between, especially if developed outside the core UI5 development teams.
o The HTML root element of every control should have this CSS class name written,
any inner HTML elements requiring a class name should use this class name and
add a suffix.
All CSS selectors written by UI5 control developers must refer to at least one such CSS
class, pure HTML elements should not be styled (to avoid affecting non-owned HTML)
Inline CSS should only be used for control instance specific style (like the button width)
Impact on Upgrade for Fiori Apps Page 11 of 20 DSAM
16-Jul-18 SAPUI5 Development Guidelines
5.3.1 Styling Contexts
When the visuals of certain controls are different depending on the context/container
where they are used, the suggested pattern to achieve this is using CSS cascades:
The area/container shall write a certain marker CSS class to the HTML and
document this CSS class in its JSDoc. The documentation should mention
the purpose and contract/meaning of this class, e.g. that it is meant to modify
the appearance of children in a way that better fits table cells, toolbars or
headers.
This CSS class may not have any CSS styles attached, it is a pure marker
(such styles would also need to stay stable and might cause trouble for other
containers where these styles are not desired)
The naming convention for these classes is to have the suffix "-CTX", e.g.
"sapUiTable-CTX" or "sapMList-CTX" or "sapUiBorderless-CTX". This makes
them easily discernible from "normal" CSS class names.
Controls which want to modify their appearance in such an area shall have
CSS where this marker class is used in a cascade and provides the suitable
style (e.g. .sapUiTable-CTX .myCompanyInputField { border: none; })
The following are the common UI elements that have been identified as part of separate reusuable
project.
Internationalization
Scrolling/Pull-to-refresh/Pagination
User Authorization
Message Handling
Common Rejection/Approval Confirmation Message
Common Utility Library
Analytical Elements
The above components will be included as part of the reusuable project. All the custom applications
will have a reference to this project to avoid duplicate code repository.
7.1.1 Introduction:
Texts in SAPUI5 Application can be translated in an ABAP system. It is a requirement
that the name of the file containing the text elements ends with '.properties' and a special
key in the format # SAPUI5 TRANSLATION-KEY <GUID with 32 characters> must be
provided in the first line (Exchange the complete palceholder <GUID with 32 characters>,
including the angle brackets, with a vaild 32char GUID).
In addition, every text element needs a classification such as the text type.
7.1.2 Overview:
The purpose of the text API in the SAPUI5 Repository is to enable an ABAP translation
process for text elements of SAPUI5 applications developed in Eclipse that are stored in
the SAPUI5 Repository.
The text elements are located in a property file (here denoted as a '<name>.properties'
file, where '<name>' stands for an arbitrary identifier).
The text elements stored in '<name>.properties' files are transferred to a database table
when a SAPUI5 application is deployed to a SAPUI5 Repository on an ABAP server.
In addition, these table entries are written to a transport request.
These texts can then be translated in the usual way.
The master language of the SAPUI5 Repository is taken as the master language for the
submitted text elements.
The translated texts can then be accessed during runtime.
The SAPUI5 Text Repository is updated each time the property file is submitted to the
SAPUI5 Repository (creation, update and deletion of texts is supported)
Text Type:
Each text element must have a text type assignment. Text types can be, for example,
XBUT for button texts, XFLD for field labels, or XTXT for general texts. A list of the
various possible text types is provided below.
7.2 Translation
SAP Note 1686090 must be implemented in the translation system to enable the translation of
SAPUI5 text elements. SAPUI5 text elements are treated as ABAP short texts with translation
object type: UI5T.
The translation object name is a GUID, which is the key taken from the original property file
containing the text elements (the GUID from the first line) (see under Prerequisites:# SAPUI5
TRANSLATION-KEY <GUID with 32 characters>). Therefore, all text elements from a property
file have the same (translation) object name.
The text key of each text element consists of the text type and an individual GUID, separated
by a blank.
The UI5T texts are stored in the following database tables (all three tables also contain an
indicator for the SAP/customer namespace):
/UI5/TREP_TEXT Master table with the text name, unique text GUID (contained in the text key
displayed in SE63), text type, additional context information, and another GUID that is the
(translation) object name (the GUID from the property file).
/UI5/TREP_TEXT_T Language-dependent table containing the original and translated text; the
key is the text GUID as in table /UI5/TREP_TEXT and the language key.
/UI5/TREP_FILES Another table, which contains the (translation) object name (the GUID from
the property file) and path information for the property file.
The UI5T translation object type needs to be assigned to the respective languages for
translation in table LXE_MASTER (table LXE_LA_OB), otherwise it will not show up in the
translation worklist.
7.3 Scrolling/Pull-to-refresh/Pagination
Because of limited size of mobile devices, scrolling is an essential topic in mobile user
experience. Smooth and easy scrolling is important for user acceptance of mobile applications.
Message Dialog:
A message dialog interrupts the user's workflow by blocking the current page and
needs to be closed by the user.
Use a message dialog if the message is important and must be acknowledged by the
user.