Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function onExit not triggering while navigating

Tags:

sapui5

While navigating from one screen to another onExit has to be called to free resources. However it is not triggered. This is my code:

function (BaseController, JSONModel, formatter, Filter, FilterOperator) {
    "use strict";

    return BaseController.extend("app.controller.Worklist", {

        _oCatalog: null,
        _oResourceBundle: null,

        onInit: function() {
            this._oView = this.getView();           
        },

        onThirdScreen : function (oEvent) {
            this.getRouter().navTo("thirdscreen", {});
        },

        onExit: function() {
            if (this._Dialog) {
                this._Dialog.destroy(true);
            }
        }

    });         

});
like image 901
anil kumar Avatar asked Apr 06 '26 06:04

anil kumar


2 Answers

As @mattbtt has mentioned, views are not destroyed each time you switch to another view so the "exit" event will not be triggered. What you can do, however, is to handle the onBeforeHide/onAfterHide events from the view instead.

onInit: function() {
    this._oView = this.getView();           
    this._oView.addEventDelegate({
        onBeforeHide: function(oEvent) {
            debugger;
        },

        onAfterHide: function(oEvent) {
            debugger;
        }
    }, this)
}
like image 92
tapsiturbi Avatar answered Apr 19 '26 11:04

tapsiturbi


This is the expected behavior as navigating via the routing mechanism does not destroy the corresponding view. This makes a lot of sense as views normally do not change during the lifespan of their parent component. Furthermore it would slow down the application if views need to be repeatedly instantiated if the corresponding route matches.

like image 44
matbtt Avatar answered Apr 19 '26 10:04

matbtt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!