Skip to Content

Formatter called multiple times from a XML view

i created a formatter to show a text from an "i18n" model.

When the page (view) starts, the function "ageDescription" inside of the formatter is called 3 times:

  1. sBirthday is "undefined"
    sFormat is "undefined"
  2. sBirthday is valorized correctly
    sFormat is "undefined"
  3. sBirthday is valorized correctly
    sFormat is valorized correctly

Why this happen?
Is correct?
How i can handle a function not managing "undefined" values?


], function (DateFormat) {
	"use strict";
	return {
		ageDescription : function (sBirthday, sFormat) {			
			var oBundle = this.getView().getModel("i18n").getResourceBundle();
			var sAge = oBundle.getText("tooYoung");
			var sFromMyBd = moment(sBirthday, sFormat).fromNow();
			return sAge;


], function (Controller, JSONModel, ResourceModel, mobileLibrary, formatter) {
	"use strict";
	return Controller.extend("controller.main", {
		formatter: formatter,
		onInit : function () {



	<Label text="{ 
		parts: [ 
			{path: '/user/birthday'}, 
			{path: '/user/dateFormat'} 
		formatter: '.formatter.ageDescription' }"

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Nov 05, 2019 at 01:14 PM


    my formatter is different:


    sap.ui.define([], function () {
    	"use strict";
    	return {
    		formatterVisiblePrest: function (FLAG, TIPO) {
    			var vis = false;
            	if (FLAG === "X" && TIPO !== "X"){
                   vis = true;  
    			return vis;


    <Button tooltip="{i18n>AggiungiAtt}" visible="{parts: [{path: 'TabAttRV>FLAG'}, {path:'TabAttRV>TIPO'}], formatter:'.formatter.formatterVisibleAtt'}" id="idAggiungiButton" enabled="{= ${TabAttRV>FLAG} === 'X'}" press="onAggiungiAttivita"
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 05, 2019 at 02:28 PM

    Hello Claudio Vicenti ,

    Can you check whether the binding is run before Model is read the data.

    I have seen a scenario where, binding happens on a action(eg : clicking on Button), in this case binding in view is already specified so, for first time when it tries to render, the value of binding can be undefined.

    Just checking , it may help you.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.