14

I'm searching the mode to execute a code (in my case the retrieve of data to visualize from server) every time I view a page (every time the page is called by splitApp.toDetail or splitApp.backDetail). How can i do it?

P.S. The onBeforeRendering and onAfterRendering execute only the first time.

1

3 Answers 3

15

There is a solution for you. There is a event called routeMatched when navigation is triggered every time. You can attach the event in the detail page.

 onInit : function () {
    this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
    this._oRouter.attachRouteMatched(this.handleRouteMatched, this);
},

handleRouteMatched : function (evt) {
    //Check whether is the detail page is matched.
    if (evt.getParameter("name") !== "detail") {
        return;
    //You code here to run every time when your detail page is called.
}
0
7

I´m using onBeforeShow in my target views for that.

onBeforeShow : function(evt) {
    // gets called everytime the user 
    // navigates to this view
},

This is a function which is fired by a NavContainer on its children in case of navigation. It´s documented in the NavContainerChild.

8
  • Did you insert onBeforeShow in your target view. Means in the view that is targeted in splitApp.toDetail(<view>)? Aug 5, 2014 at 14:36
  • yes, i replace onBeforeRendering with onBeforeShow. Now the code is never executed
    – padibro
    Aug 5, 2014 at 14:40
  • Ok I tried it again and it works. In this page it´s described to manually subscribe to this event. You could try this otherwise you can show us some more code (split app, views). Aug 6, 2014 at 7:45
  • but on your application runs without registers for beforeShow event? I only replace onBeforeRendering with onBeforeShowbut not register a view by this.addEventDelegate({ onBeforeShow: function(evt) {...
    – padibro
    Aug 7, 2014 at 9:13
  • 2
    I register into onInit... it work... //INIT onInit: function() { //to register for beforeShow event this.getView().addEventDelegate({ // not added the controller as delegate to avoid controller functions with similar names as the events onBeforeShow : jQuery.proxy(function(evt) { this.onBeforeShow(evt); }, this) }); }, onBeforeShow : function(evt) { alert("onBeforeShow"); },
    – padibro
    Aug 7, 2014 at 9:24
5

If routing is used, another version of Allen's code:

 onInit : function () {
   this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
   this._oRouter.getRoute("detail").attachMatched(this.handleRouteMatched, this);
},

  handleRouteMatched : function (evt) {
    //You code here to run every time when your detail page is called.
  }
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.