Skip to Content
0

Navigation between View 1 and View 2

Jun 12 at 09:49 PM

59

avatar image

Hello SAP UI5 experts,

I have a very basic question.

I have 2 XML views, View1 and View2. Below is my code for the two controllers.

View1 Controller:

onNavToView2 {

Navigate to View 2;

setOModel(Input);

oModel Refresh();

}

View2 Controller:

onInit{

AddDynamicControlsToView2();

}

onNavBack{

detroyDynamicControls();

Navigate To back Hash;

}

I want to perform the below steps to my application:

Step1. Provide Input 1

Step2: Click on NavToView2

Step3: After View2 display, Click on NavBack

Step4: Provide Input 2

Step5: Click on NavToView2

After Step 5, how to create my dynamic controls to view2 as the "onInit()" is not triggered for second time. Is there any other option other than using a base controller or by using another js file. Do we have any browser methods to use just like onInit().

Please Help me.

Thanks

Divya

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Srikanth KV Jun 12 at 10:55 PM
1

init() method will be called only once when the first time view is initialized.

you need to use 'routeMatched' event ....this will be called anytime this route is accessed..

check the below tutorial

https://sapui5.hana.ondemand.com/#/topic/f96d2522a5ca4382a274ae3c6d002ca0

attach the event handler for the route in init() method:

var oRouter = this.getRouter();
oRouter.getRoute("employee").attachMatched(this._onRouteMatched, this);     // route name = employee
         // _onRouteMatched - event handler ...which is called everytime the route 'employee' is accessed

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you, Srikanth. It worked.

0
Divya Vannala Jun 13 at 02:42 PM
0

Thank you, Srikanth.

I will try it. And let you know.

Regards

Divya

Share
10 |10000 characters needed characters left characters exceeded