Skip to Content

util.Formatter.js function in JS View

Hi Expert.

I am trying to complete "Building SAP Fiori-like UIs with SAPUI5" exercise 3 in JS view.

I have problem in calling statusText function of util.Formatter.js in my Detail.view.js.

The original exercise is in xml view.

Below is my codes..

Formatter.js

jQuery.sap.declare("myFioriApp.util.Formatter");
myFioriApp.util.Formatter = {
statusText : function(value) {
var bundle = this.getModel("i18n").getResourceBundle();
return bundle.getText("StatusText" + value, "?")
}
}

Detail.view.js

sap.ui.jsview("myFioriApp.Views.Detail", {
getControllerName : function() {
return "myFioriApp.Views.Detail";
},
createContent : function(oController) {
var oHeader = new sap.m.ObjectHeader({
firstStatus: new sap.m.ObjectStatus(
{text:{
formatter: function(s){
return myFioriApp.util.Formatter.statusText(s)
}}})}
}

Function statusText() did get called but (this.) does not have an instance of text control therefor it fails to call getModel() function of it's aggregate.

Thanks in advance for your reply.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Apr 16, 2016 at 07:57 PM

    Hi Edwin

    {
       text: {
          path: '?',  
          formatter: function(s){  
             return myFioriApp.util.Formatter.statusText(s)  
          }
       }
    }  
    

    path is missing

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 18, 2016 at 01:38 AM

    Hi Edwin, Please load the dependency. jQuery.sap.require("myFioriApp.util.Formatter"); Thanks, Manoj

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 18, 2016 at 04:32 AM

    Currently my workaround is to pass the text's object from the view to Formatter.js but I believe there must be a better answer out there.

    Formatter.js

    jQuery.sap.declare("myFioriApp.utility.Formatter");
    myFioriApp.utility.Formatter = {
    statusText: function(textObject,value){
    var bundle = textObject.getModel("i18n").getResourceBundle();
    return bundle.getText("StatusText" + value, "?")
    }}
    

    Detail.view.js

    sap.ui.jsview("myFioriApp.Views.Detail", {
    getControllerName : function() {
    return "myFioriApp.Views.Detail";
    }},
    createContent : function(oController) {
    var oHeader = new sap.m.ObjectHeader({
    firstStatus: new sap.m.ObjectStatus({text:
    {path: "LifecycleStatus",
    formatter: function(s){
    return myFoioriApp.utility.Formatter.statusText(this, s)
    }
    }
    })})
    }
    
    Add comment
    10|10000 characters needed characters exceeded