0

I have two views: Login and Menu.

Scenario:

Log in --> onInit() , onBeforeRendering() , onAfterRendering() gets called in Menu.controller.js and go to the Menu view.

Log out --> deleteData(); oRouter.navTo("Login", {}, true); Back to the login view.

Log in --> onInit() , onBeforeRendering() , onAfterRendering() doesn't get called and go to the Menu view.

I've tried to attach my Menu controller to a specific route in onInit but it doesn't work:

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

How to forcefully call the above methods again? I need to reload the method initMenu() which is in the onInit() function to receive the menu correctly.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Angel Silvan
  • 83
  • 11

2 Answers2

2

onInit is called one time only. Its life cycle method of Sapui5. If you want a function which will get called every time you navigate then use onAfterRendering or onBeforeRendering. Other wise create function and call that function from route match.

above route match should be like this.

this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
 this._oRouter.attachRouteMatched(this.yurfunction, this);

//now do as below

yurfunction(){ //now give call to you function from here }
  • I've tried both things but they don't work. If I call that function from route match it's also run when I log out. If I use onAfterRendering or onBeforeRendering nothing happens because the page doesn't rerender. – Angel Silvan Mar 01 '17 at 09:34
  • well that is only what problem with route match create one global variable and assign make it true once function is executed make that global variable false. sap.ui.getCore().urVariable=true;do this in onInit. Now if(sap.ui.getCore().urVariable){// you stuff.sap.ui.getCore().urVariable=false; } set it to false. – suryabhan mourya Mar 01 '17 at 09:42
0

You can look into onBeforeShow() method of a view. This lifecycle hook will be called everytime a view is displayed. You can do your operations here. See : https://openui5.hana.ondemand.com/#docs/api/symbols/sap.m.NavContainerChild.html

Rahul Bhardwaj
  • 2,303
  • 1
  • 17
  • 28