0
votes

I am trying to create a splitapp with the details view having a map updated based on the selection from the master view. Currently I am trying to set a Model in a function that is executed on select of a list item. I am setting the required model using sap.ui.getCore().setModel(oModel, "ModelName"); in the master controller. And in the details controller I am trying to access the model using sap.ui.getCore().getModel("ModelName").getData();. But, sap.ui.getCore().getModel("ModelName") is coming out as undefined.

2

2 Answers

1
votes

It's recommended to build Component based UI5 applications. If you do so, you can do the model initialization in the component's init function:

init: function() {
    // call the init function of the parent
    UIComponent.prototype.init.apply(this, arguments);
    // set data model
    var oData = {
        prop: test
    };
    var oModel = new JSONModel(oData);
    this.setModel(oModel);
}

If you are using manifest.json, it's much better to define your model there; this model will be available through the whole application; including views and controllers like the i18n or device models which are created similarly.

Setting up the component.js, Application descriptors on UI5 Walkthrough page.

0
votes

If you would like to have a global model I will suggest you to use the Component as main holder.

In each Controller you can do

this.getOwnerComponent().setModel(oModel, sModelName);

and than retrieve it with

this.getOwnerComponent().getModel(sModelName);

Views and Controllers have their own model visibility so it would be local.