<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="UTF-8">
<title>Walkthrough</title>
<script
id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"sap.ui.sample": "./"
}' >
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.xmlview({
viewName : "sap.ui.sample.App"
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
Register the view with the message manager and let it validate its content (that is what the 'true' flag means)
API doc for MessageManager: https://sapui5.hana.ondemand.com/sdk/#docs/api/symbols/sap.ui.core.message.MessageManager.html
Unfortuantely, I have not found any other documentation about this
When you now enter a non-number string into the input field which is defined in the view and press return or have the focus leave
the input will have its sap.ui.model.type.Integer validate the content and display an error message.
<mvc:View
controllerName="sap.ui.sample.App"
xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc">
<Input
value="{
parts: [
{path:'/age'},
{path:'/properties/numberStyle'},
{path:'/properties/decimalPlaces'}
],
formatter: '.floatFormat'
}"/>
<Select
forceSelection="false"
selectedKey="en"
items="{
path: '/locales',
sorter: { path: 'name' },
factory: '.createContent'
}">
</Select>
<Select
forceSelection="false"
showSecondaryValues= "true"
selectedKey="en"
class="kfLocaleSelect"
items="{
path: 'locales>/',
sorter: { path: 'name' },
factory: '.createArrContent'
}">
</Select>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/ui/model/resource/ResourceModel",
"sap/ui/core/format/NumberFormat"
], function (Controller, JSONModel, ResourceModel, NumberFormat) {
"use strict";
return Controller.extend("sap.ui.sample.App", {
onInit : function () {
// Register the view with the message manager and let it validate its content
// (that is what the 'true' flag means)
// API doc for MessageManager: http://veui5infra.dhcp.wdf.sap.corp:8080/demokit/#docs/api/symbols/sap.ui.core.message.MessageManager.html
// Unfortuantely, I have not found any other documentation about this
//
// When you now enter a non-number string into the input field
// which is defined in the view and press return or have the focus leave
// the input will have its sap.ui.model.type.Integer validate the content
// and display an error message
sap.ui.getCore().getMessageManager().registerObject(this.getView(), true);
var oPersonData = { number: "Andrew", age: 3412312.2234, city: "Walldorf",
properties: {
"decimalPlaces": "1",
"numberStyle": "short",
},
locales:{
"de": {
"properties": {
"decimalPlaces": "2",
"description": "Motortemperatur",
"timePeriod": "Diese Woche",
"title": "Durchschnittliche Motortemperatur",
"uom": "°C"
}
},
"en": {
"properties": {
"decimalPlaces": "3",
"description": "Average Temperature of Front Motor",
"timePeriod": "Current Year",
"title": "Average Temperature of Front Motor",
"uom": "°C"
}
}
},
arrLocales:[
{
"name": "de-AT"
},
{
"name": "de-DE"
},
{
"name": "en-US"
},
{
"name": "en"
},
{
"name": "de"
}
]
};
this.getView().setModel(new JSONModel(oPersonData));
var oLocalesData = {
arrLocales:[
{
"name": "de-AT"
},
{
"name": "en"
},
{
"name": "de"
}
]
};
//Merge supported and available locales into and array
var aMergedLocales = [];
//First add all supported locales
for (var key in oPersonData.locales) {
aMergedLocales.push(key);
}
//Make a copy of the array: these are supported languages
//and we will use this copy to check if available languages
//are contained
var aSupportedLocales = aMergedLocales.slice();
//Now add a token to generate a separator
aMergedLocales.push("separator");
//Finally add all languagues from 'arrLocales' if they
//are not in the list of supported languages
jQuery.each(oPersonData.arrLocales,
function(index, value) {
var key = value.name;
if(jQuery.inArray(key, aSupportedLocales) === -1) {
aMergedLocales.push(value.name);
}
});
//finally create a JsonModel named 'locales' for ournew array
this.getView().setModel(new JSONModel(aMergedLocales), "locales");
},
floatFormat : function(sAge, sStyle, sDecimalPlaces) {
var oFloatFormatter = NumberFormat.getFloatInstance({
style: sStyle,
minFractionDigits: sDecimalPlaces,
maxFractionDigits: sDecimalPlaces,
parseAsString: true
});
return oFloatFormatter.format(sAge);
},
createContent: function(sId, oContext) {
var sPath = oContext.getPath(),
sLocale = sPath.slice(sPath.lastIndexOf('/') + 1);
//example for sPath: /locales/de-AT
return new sap.ui.core.Item(sId, {key: sLocale, text: sLocale});
},
createArrContent: function(sId, oContext) {
//var sPath = oContext.getPath(),
// sLocale = sPath.slice(sPath.lastIndexOf('/') + 1);
//example for sPath: /locales/de-AT
var name = oContext.getObject().name,
result;
result = new sap.ui.core.Item(sId + "arr", {key: oContext.getObject().name, text: oContext.getObject().name});
return result;
}
});
});
theyLiveIn={0} lives in {1}