0

I have a SAPUI5 panel which can be destroyed indirectly in various circumstances for various reasons (e.g. in this example, that parent of the parent is destroyed). Therefore, I must use a function hook coming from the control itself.

I tried to call the exit function (base on this Stack Overflow question and this SAPUI5 documentation)

var oGrandParentPanel = new sap.m.Panel();
var oParentPanel = new sap.m.Panel();
var oPanel = new sap.m.Panel({
    exit: function(){
        alert("FOOBAR!");
    }});

oParentPanel.addContent(oPanel);
oGrandParentPanel.addContent(oParentPanel);
oGrandParentPanel.destroy();

I want a "FOOBAR!" alert, but I am not getting it.

Community
  • 1
  • 1
Daniël Camps
  • 1,737
  • 1
  • 22
  • 33

1 Answers1

2

I think your confusing lifecycle methods with events. Lifecycle methods are defined within the control and the control can either implement them or not. Events are hooks that you could bind your own functionality to.

If you would like to have a panel that calls an event (that you could attach your own logic to), you could subclass the panel control. You could define a new event in the metadata and in the onExit method, you could then fire that event.

If you are interesting in quickly doing something when the user closes the browser, you there is also both window.onbeforeunload and window.onunloadthat you could use. Unfortunately, they are not 100% browser independent and there is not guarantee that they will be called at all.

jpenninkhof
  • 1,920
  • 1
  • 11
  • 12