Skip to Content

How to send JSON model from one view controller to another view controller .??

Aug 08, 2017 at 05:58 AM


avatar image


I need to fetch JSON model of one view and need to use it in another view controller, I have used sap.ui.getCore().setModel(). But some of them are suggested that its not best practice to set model to core.

So is there any other way to send JSON model to another view controller.

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

3 Answers

Juan Torres Aug 08, 2017 at 06:46 PM

Like Saurabh said, you could declare the model in the Component.js and set it (this.setModel("modelName")) and then create an instance using this.getOwnerComponent().getModel("modelName") in the controller where you want to use it.

10 |10000 characters needed characters left characters exceeded
Yogesh Beria
Aug 08, 2017 at 02:53 PM

Possible with what Saurabh mentioned above.

But you also need to take care that the UI flow always goes through the view where the model is being set.

Otherwise, if you navigate to the view which consumes the model directly via the URL, the model won't be available.

10 |10000 characters needed characters left characters exceeded
saurabh vakil Aug 08, 2017 at 06:07 AM

Either declare your JSON model in the Component.js file or within the manifest.json file. Models declared within any of these are globally available within the entire application. Refer SAPUI5 SDK

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

I am getting data on 2 view on some conditions by passing filter to URL, I need that data in 3 view.

So I can't set model in component.js


You should do the following:

- on the component var oModelEx = new JSONModel(); this.setModel(oModelEx, "oModelEx");

- on the 2 view var oModelEx = this.getOwnerComponent().getModel("oModelEx"); oModelEx.setProperty("/property", value)

- on the 3 view var oModelEx = this.getOwnerComponent().getModel("oModelEx"); var sProperty = oModelEx.getProperty("/property");

I hope this could help you.


You can then set the model to the view. this.getView().setModel("<model>")