0
votes

I want to load a Model in my onInit Method, before the onBeforeRendering Method is called. The problem withe attachRequestCompleted is that this called sometime after Rendering. For example i get this error withe the ProcessFlow:

Render must not be called within Before or After Rendering Phase. Call ignored. -  [object Object]

So my question is: Give it a function that block the view until the model ist loading?

I instantiated my Views over a manifes.json and my Models in the Component.js. So show Code is a bit difficult, but i load my Model like this:

 var oModel = new JSONModel().attachRequestCompleted(function(){...});
 var oConfigModel = new JSON().attachRequestCompleted(function(){
       oModel.loadData(oConfigModel.getURL());
 });
 oConfigModel.loadData("config.json");

I do this because i formating and make some Models in dependency of my Main Model. And Currently i put the data in the ProcessFlow over Databinding in the xml.

2
can you make the Model request syncronous ?Rahul Bhardwaj
Please, show us some code (in the question) how you bootstrap, and especially how your views and controllers are defined and instantiated.Boghyon Hoffmann
i have edit the question.TheRadianer

2 Answers

1
votes

Blocking the UI never is a good idea! Esp. doing synchronous request as suggested in comments is aweful. Syncronous request are even deprecated on the main thread in major browsers.

You could set your view busy or even invisible until your model data is loaded like this:

onInit: function() {
  var oView = this.getView();
  oView.setBusy(true);
  // option 2 set invisible: oView.setVisible(false);

  ... insert model init here ...
  var oModel = ...
  oModel.attachEventOnce("requestCompleted", function() {
    oView.setBusy(false);
    // option 2 set visible: oView.setVisible(true);
  });
}

Note the use of attachEventOnce instead of attachRequestCompleted that will only execute - guess what - once.

Btw: Why is it so important to block or not show the UI at all? It is a much better experience for a user to already see sth. eventhough a view might be empty initially.

BR Chris

0
votes

An option here could be to use a busy indicator.

Start the indicator in your init function:

sap.ui.core.BusyIndicator.show();

...and stop the indicator in your attachRequestCompleted callback function:

sap.ui.core.BusyIndicator.hide();

More information here.