Skip to Content
0

My scenario is i want to show entered input value in view1 to the input box of view2 ?

Feb 28, 2017 at 10:00 AM

214

avatar image

i scenario is i want to show the input value of the View1 in to the View2?

- i have created the json model in the view and stored the input value in to the json model and assigned that json model in to thhe global var.

- in view2 i used that global var.

- But in view2 input box the value is not shoowing i did binding also.

View1 Code:

View1.Controller.js

View2.XMl

View2.controlle.js

v1.png (11.3 kB)
v2.png (9.0 kB)
v1.png (11.3 kB)
v2.png (9.0 kB)
1.png (41.5 kB)
2.png (52.7 kB)
3.png (39.6 kB)
4.png (45.0 kB)
10 |10000 characters needed characters left characters exceeded

var g_model ;

i defined in View2 controller and used.

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
SACHIN R Mar 01, 2017 at 11:08 AM
0

hi i tried i got for only one time by placing it in the on init function below code.

now another issue is how to make these code should be called every time before loading the view and how to clear the input field while exiting view2. i tried with the other events also like onbeforerendering and after since they load only one time it not possible to use.

var temp = g_model ;
 var oInput = this.getView().byId("InP02");
 var temp2 = temp.getData().myValue;
 oInput.setValue(temp2);
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Use sap.m.Router event patternMatched in onInit method of controller (this event will be called every time you come to this view2)

Assuming that route name to navigate to view2 is rtView2

onInit: function() {
   var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
   oRouter.getRoute("rtView2").attachPatternMatched(this.onRouteMatched, this);
},

onRouteMatched: function(oEvent){
    //Write code that needs to be executed when View2 is shown
}
0

hi i tried use attachPatternMatched and onRouteMatched but it gave error in my program.So i have creted a one More Button as REFRESH and i placed those code in that button press event it worked fine.

Refresh: function(Eevent) {
var temp = g_model;
var oInput = this.getView().byId("InP02");
var temp2 = temp.getData().myValue;
oInput.setValue(temp2);
// console.log(temp.getData().myValue);
},
0
Srikanth KV Feb 28, 2017 at 05:37 PM
1

When you want to access data across two views or more then you should have a common area/memory/model/variable to share the data across all the views.

In your case g_model is set in view1, imagine g_model as a variable.....can you access a variable defined in one file into another file....that is not possible.

Now the next question is where to define model(g_model)? ....we need to identify the root of "view1" and "view2", this root will most probably "Component.js" or "index.html". If you place the model in this root then it can be accessed in all the views.

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

HI,

Thanks for your comments
but console statement in the view2 controller returns the actual value which i have entered in view1.

if it is not g_model accessible than the console statement should return empty.

console.log(temp.getData().myValue);

5.png (21.3 kB)
0