cancel
Showing results for 
Search instead for 
Did you mean: 

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

sachinrk
Explorer
0 Kudos

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

sachinrk
Explorer
0 Kudos

var g_model ;

i defined in View2 controller and used.

Accepted Solutions (1)

Accepted Solutions (1)

sachinrk
Explorer
0 Kudos

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);
former_member365727
Active Contributor
0 Kudos

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
}
sachinrk
Explorer
0 Kudos

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);
},

Answers (1)

Answers (1)

former_member365727
Active Contributor

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.

sachinrk
Explorer
0 Kudos

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);