-1

So I'm trying to recreate this app on SAP Web IDE:

app

But I'm continuously getting this error:

enter image description here

This is my App.Controller.js code:

sap.ui.define([
    "pt/procensus/ui5rv/controller/BaseController",
    "sap/ui/model/json/JSONModel"
], function (BaseController, JSONModel) {
    "use strict";

    return BaseController.extend("pt.procensus.ui5rv.controller.App", {

        onInit : function () {
            var oViewModel,
                fnSetAppNotBusy,
                oListSelector = this.getOwnerComponent().oListSelector,
                iOriginalBusyDelay = this.getView().getBusyIndicatorDelay();

            oViewModel = new JSONModel({
                busy : true,
                delay : 0
            });
            this.setModel(oViewModel, "appView");

            fnSetAppNotBusy = function() {
                oViewModel.setProperty("/busy", false);
                oViewModel.setProperty("/delay", iOriginalBusyDelay);
            };


            this.getOwnerComponent().oWhenMetadataIsLoaded.
                then(fnSetAppNotBusy, fnSetAppNotBusy);

            // Makes sure that master view is hidden in split app
            // after a new list entry has been selected.
            oListSelector.attachListSelectionChange(function () {
                this.byId("idAppControl").hideMaster();
            }, this);

            // apply content density mode to root view
            this.getView().addStyleClass(this.getOwnerComponent().getContentDensityClass());
        }

    });

}
);

This is my Base.Controller.js code:

    /*global history */
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History"
], function(Controller, History) {
"use strict";

return Controller.extend("pt.procensus.ui5rv.controller.BaseController", {
    /**
     * Convenience method for accessing the router in every controller of the application.
     * @public
     * @returns {sap.ui.core.routing.Router} the router for this component
     */
    getRouter: function() {
        return this.getOwnerComponent().getRouter();
    },

    /**
     * Convenience method for getting the view model by name in every controller of the application.
     * @public
     * @param {string} sName the model name
     * @returns {sap.ui.model.Model} the model instance
     */
    getModel: function(sName) {
        return this.getView().getModel(sName);
    },

    /**
     * Convenience method for setting the view model in every controller of the application.
     * @public
     * @param {sap.ui.model.Model} oModel the model instance
     * @param {string} sName the model name
     * @returns {sap.ui.mvc.View} the view instance
     */
    setModel: function(oModel, sName) {
        return this.getView().setModel(oModel, sName);
    },

    /**
     * Convenience method for getting the resource bundle.
     * @public
     * @returns {sap.ui.model.resource.ResourceModel} the resourceModel of the component
     */
    getResourceBundle: function() {
        return this.getOwnerComponent().getModel("i18n").getResourceBundle();
    },

    /**
     * Event handler  for navigating back.
     * It checks if there is a history entry. If yes, history.go(-1) will happen.
     * If not, it will replace the current entry of the browser history with the master route.
     * @public
     */
    onNavBack: function() {
        var sPreviousHash = History.getInstance().getPreviousHash();

        if (sPreviousHash !== undefined) {
            // The history contains a previous entry
            history.go(-1);
        } else {
            // Otherwise we go backwards with a forward history
            var bReplace = true;
            this.getRouter().navTo("master", {}, bReplace);
        }
    }

});

});

My App Folders:

enter image description here

And I can't understand why is this happening. I've already removed the 'then' part and it gives me more errors... :/

Any help will be very much appreciated :)

André Gomes
  • 59
  • 1
  • 9

1 Answers1

0

Can you try this? At least this is how it works in my App.controller:

 this.getOwnerComponent().getModel().metadataLoaded()
            .then(fnSetAppNotBusy, fnSetAppNotBusy);
Thomas L.
  • 249
  • 2
  • 15
  • It didn´t work.. The error message is 'Cannot read property 'metadataLoaded' of undefined' – André Gomes Jul 13 '17 at 10:44
  • Can you please post your Base Controller Code? – Thomas L. Jul 13 '17 at 10:45
  • So it seems that your default (perhaps OData) model is undefined. If you log the model in the console, what does it say? – Thomas L. Jul 13 '17 at 11:26
  • Sorry for the delay, but if i did everything right is says undefined – André Gomes Jul 13 '17 at 13:25
  • Did you put in a default model in your manifest.json file? It seems like there is no default model and therefore the .getModel() function returns undefined. – Thomas L. Jul 13 '17 at 13:37
  • I dont have an manifest file. Im going to ulpload the folders i have – André Gomes Jul 13 '17 at 13:44
  • Okay that seems to be the problem. The manifest.json file defines the default model of your application. Please look up the SAPUI5 Walkthrough if you don't know how to build up your application: [link]https://openui5beta.hana.ondemand.com/#docs/guide/8f93bf2b2b13402e9f035128ce8b495f.html – Thomas L. Jul 13 '17 at 13:51
  • 1
    Addition: If you don't want to initialize the manifest.json you could also implement the model instantiation in the Component.js. This is also described in the Walkthrough – Thomas L. Jul 13 '17 at 13:52