cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to get notified about an SAPUI5-App leave event in Fiori Launchpad?

former_member306541
Participant
0 Kudos

Hi all,

I need a notification in FLP about every event, that my SAPUI5-App is going to be left by the user. My requirement is, that the user should be asked to save unsaved changes, before the leave event is executed.

So far I can identify three kinds of events:

  1. Events within my SAPUI5-App
    These are not hard to find and I am able to react to Cross-App-Navigation triggers etc.
  2. Events within FLP
    There are Back- and Home-Buttons and the App-Navigation in the top-middle of the screen. How can register to those events and prevent the original coding from executing?
  3. Events within the browser
    The browser or tab can be closed or another tab can be selected. I guess, that there are some kind of window events for this, but I have to search for them.

Any suggestions for 2. and 3. are welcome.

Thank your very much und best regards,

Christian.

Accepted Solutions (1)

Accepted Solutions (1)

jorge_cabanas
Participant

Hi Christian,

1- Solved as you said.


2- How register these events?

sap.ui.getCore().byId('homeBtn').attachPress(function() {        
   // Here your code
});

sap.ui.getCore().byId('backBtn').attachPress(function() { // Here your code });

How prevent the original coding execution?
Typing the next line in the functions above

sap.ui.getCore().getEventBus().destroy();


3- How capture browser events?
You can manage any URL change with the "Data Protection Loss" provided from SAPUI5. It's so easy as setting a flag variable and getting it after. Please refer to the next link: Data Loss Protection

I hope it helps you 🙂

Kind regards,
Jorge.

jorge_cabanas
Participant
0 Kudos

Hi Christian,

Did it help you?

Kind regards,
Jorge

former_member306541
Participant
0 Kudos

Hi Jorge,

thank you very much for your answer! I am sorry, that I could not answer earlier.

Attaching a listener to HomeBtn and BackBtn is what i was looking for. But when I call sap.ui.getCore().getEventBus().destroy(); in the first line of my callback function, the browser still executes one step back in history. When I set a breakpoint in my callback function I can see, that the chrome debugger stops for a short time and after that it loads the previous page and my js code stops executing.

Do you ever have a similar experience?

Best regards,

Christian.

jorge_cabanas
Participant
0 Kudos

Hi Christian,

I'm afraid I didn't have that experience...

Just to try, code something similar:

sap.ui.getCore().byId('backBtn').attachPress(function(oEvent) {        
    oEvent.preventDefault();
});

Kind regards,
Jorge

former_member306541
Participant
0 Kudos

Hi Jorge,

it was a misconfiguration of my test setting. I loaded the App on my FLP in debug-mode. So there was no history entry for the flp and in this case the flp does a browser history back and the browser loads the previous page from scratch.

When I first load the FLP Startpage in debug mode and navigate to my app, then the back button calls my function and I can destroy the event.

Do you know, how do I best listen to URL changes? Do I use HashChanger and attach to the "hashChanged" event?

Best regards,

Christian.

former_member306541
Participant

Hi Jorge,

I should have started with Data Loss Protection (-; As you said, that's everything I wanted! But it is badly documented and I did not understand it right away.

Thank you very much!

Best regards,

Christian.

Answers (0)