on 02-07-2016 3:04 AM
Hi,
I have created a JSON model and bind the same into sap.ui.getCore().setModel.
var json = {};
json.plant = plant;
json.sloc = sloc;
json.material = material;
this.materialset.setData(json);
sap.ui.getCore().setModel(this.materialset,"materialset");
and the same is accessed in other view
var materialset=sap.ui.getCore().getModel("materialset");
var mSet=materialset.getData()
var fplant=mSet.plant;
var fsloc=mSet.sloc;
var fmat=mSet.material;
Im able to get all the data from JSON model.
But when i refresh the browser from 2nd view, its throwing error message in
materialset.getData()
It seems the data which I passed from 1st view got removed by browser refresh.
Wont it be reside in object even after browser refresh or is it the usual functionality ?
I need to get the values even after page refresh. help me to get a solution.
Thanks
Yokesvaran Kumarasamy
You should set model at application level.
Are you setting model in 1stview or Component.js ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Abdul Waheed
Thanks for your reply.
Initially it was in 1st view. Now I changed that into components.js.
And i have set empty values in component.js
var materialset = new sap.ui.model.json.JSONModel();
var json = {};
json.plant = '';
json.sloc = '';
json.material = '';
json.mmbFlag = '';
materialset.setData(json);
materialset.setDefaultBindingMode("TwoWay");
sap.ui.getCore().setModel(materialset,"materialset");
Later in 1st view im giving values to the same model
this.materialset =sap.ui.getCore().getModel("materialset");
var json =this.materialset.getData();
json .plant = plant;
json .sloc = sloc;
json .material = materialList;
json .mmbFlag = getsegbtnId_value;
//this.materialset.setData(mSet);
this.materialset.updateBindings(true);
this.materialset.refresh();
When im navigating to 2nd view its working fine. But again when i hit F5 refresh, its not recognizing the data and its fetching empty data from component.js
Any idea where i did mistakes?
Regards
Yokesvaran Kumarasamy
Hi Abdul Waheed
2n option is opted out. Bcz my second view is a master and detail page. When end user select list item from master page, URI parameters and detail page will change. So i cant set URI parameters.
I will try the 1st option.
But wts wrong with my code?
cant we change the JSON model data which is declared in component.js ?
Thanks & Regards
Yokesvaran Kumarasamy
Hi,
The solution I proposed in http://scn.sap.com/thread/3850447 works only if you set your model in component.js or if view 1 is loaded before view 2.
So maybe you have to tranfer the coding from view 1 to a helper function. In view 2 you should check if the model is initialized correctly and if not call the helper function.
Best regards,
Sebastian
Yes, i have set the Json model in components (you can see the code in above thread) and im changing the value of JSON model in View1 and passing to View 2. But its not working on refresh
Can you explain whats value helper functions and how to achieve it?
Thanks & Regards
Yokesvaran Kumarasamy
Hi Jun Wu,
I cant access the 2nd view directly, based on the input from 1st view im doing some functionalities in 2nd view.
So somehow i need to pass data from 1st view to 2nd view.
Regards
Yokesvaran Kumarasamy
Hi,
Declaring everything in URI parameter is the right solution.
Additionally, i have added 2 entities in component.js so URI will have two sets of entity, which i execute again when page refresh.
subroutes: [{
pattern: "{entity}/{data}",
name: "detail",
view: "Detail",
//add target aggregation to detail view
targetAggregation: "detailPages"
}]
},
Regards
Yokesvaran Kumarasamy
Hi Yokesvaran,
JSON model is client model, so when you refresh the client, it also loses all the data it holds.
This is the reason when you try to access 2nd view, you run into error.
To best resolve the issue, as someone previously mentioned that you have to shared the data either through context, which will actually exchange the data with the second view in the request itself or create the model during initialization.
The model has to be set in such method which will always be called when you launch the view.
Thanks
Prashil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for you reply.
Can you explain how to share the data through context?
is that mean, i have to store somewhere in backend and then we can fetch and use in other view ?
Regards
Yokesvaran Kumarasamy
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.