2
votes

Is there any way by which we can reload the whole SAPUI5 application?

When a SAPUI5 app is called, onInit() function is called and we are initializing some settings for view here. Say if some change (like selection of a checkbox in master view) requires the whole application to be reset, can we reload the application and call onInit() function again to correct our initial settings? Is there any trigger mechanism by which we can call onInit() function explicitly?

Thank you in advance for your suggestions.

Regards, Raja

3
When you really want to reset the whole thing you can take a look at location.reloadherrlock
With databinding a reload shouldn't be necessary. You can update your page depending on the loaded data in a e.g. formatter function.Dominik Feininger

3 Answers

3
votes

If you have the need to reload or reset your application, then I would think your app suffers from a major design flaw... This is definitely something I would look into first if I were you!

However, to answer your question, why not move the initialization code into its own function, and call that function from the onInit() event handler and whenever you need to reset your app?

1
votes

I suggest you to use some kind of intercommunication (e.g.: EventBus) between your Controller instances, from the master view notify your Controllers to rerun initialization logic like follows:

  1. move you initialization logic to separate functions on each Controller and call this method upon onInit
  2. in onInit subscribe to reinitialize event
  3. in you master view add a listener function to the mentioned checkbox selection event, and publish the reinitialize event to notify your Controllers to reinitialize

Controller.js:

function onInit() {
    this._initialize();
    EventBus.subscribe('reinitialize', this._initialize);
}
funcion _initialize() {
    // init logic
}

MasterController.js:

function onSelectionChange() {
    EventBus.publish('reinitialize');
}
1
votes

Sometimes you cannot directly use the window global variable in sapui5.

Refer to this page: https://help.sap.com/viewer/825270ffffe74d9f988a0f0066ad59f0/CF/en-US/7d0dba71a2cb45ebb1959daba904ca99.html?q=location%20reload

var myLocation = location;
myLocation.reload();