Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How execute code every time that I view a page

Tags:

sapui5

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.

like image 355
padibro Avatar asked Aug 05 '14 13:08

padibro


3 Answers

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.
}
like image 70
Haojie Avatar answered Nov 11 '22 15:11

Haojie


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.

like image 20
Tim Gerlach Avatar answered Nov 11 '22 17:11

Tim Gerlach


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.
  }
like image 5
danpop Avatar answered Nov 11 '22 17:11

danpop