SAPUI5 Guidelines
SAPUI5 Guidelines
22.Routing 16
Boolean bName
Float fName
Integer iName
String sName
Object oName
Function fnName
Map mName
● all
● debug
● error
● fatal
● info
● none
● warning
● trace
1. For Variable
sEmployeeGroup = "EmployeeData!";
2. For Function
function sayNow() {
sap.base.Log.info("abc")
};
Don’t use or override private and protected functions . Private function are
typically prefixed with “_” where as protected functions are indicated by a
yellow diamond in front of the function name.
1. //private variable in the controller object
_sPrivateVariable = “abc” ;
<Button id="sap-m-button-id"
press="onButtonPress">
</Button>
● Controller of View1
return Controller.extend("com.EventBus.EventBus.controller.View1", {
onInit: function () {
var oEventBus = sap.ui.getCore().getEventBus();
oEventBus.subscribe("_onButtonPress",
this._onButtonPress, this);
},
onButtonPress: function () {
var oData = {
message: "View's 1 button was clicked."
};
var oEventBus = sap.ui.getCore().getEventBus();
oEventBus.publish("_onButtonPress", oData);
},
_onButtonPress: function (oChannel, oEvent, oData) {
var sMessage = oData.message;
sap.m.MessageToast.show(sMessage);
}
});
● Controller of View2
sap.ui.controller("com.EventBus.EventBus.controller.View2", {
onButtonPress: function() {
var oData = {
message: "View's 2 button was clicked."
};
var oEventBus = sap.ui.getCore().getEventBus();
oEventBus.publish("_onButtonPress", oData);
}
});
● If an Xml has only one attribute then don’t give line break
<ActionButton title=”{i18n>employee}”/>
var oModel=this.getView().getModel(“i18n”);
var oResourceBundle= oModel.getResourceBundle();
var sText=oResourceBundle.getText(“abc”);
11. Model View Controller
var oModel=this.getView().getModel();
oModel.setProperty(“/message”,”hello”);
oModel.setProperty(“/alignment”,”End”);
oModel.setProperty(“/busy”,true);
oModel.setProperty(“/message”,”hello”);
//auto update all controls with binding
Hard coding Ui strings will exclude them for translation .In addition ,
concatenating translatable strings in applications might lead to errors in
i18n : the texts in question might have a different translation order in other
languages and will then be syntactically wrong.
For example,
function outer(c, d) {
var e = c * d;
if (e === 0) {
e++;
}
for (var i = 0; i < e; i++) {
// do nothing
}
function inner(a, b) {
return (e * a) + b;
}
1. Naming Targets
Targets and routes should match view file to easily track the flow of
the navigation. Also provide the following minimal settings for targets :
● viewLevel - sets hierarchy to the application views
● viewName
● viewType
● transition - the default transition behavior for the current target
● bypass - fail safe target for unmatched routes
2. Creating Patterns
Route name should be descriptive by itself .Prefer plural form of
routes if applicable.