cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Best Practice For Data Transfer Between Views

fikretsomay
Participant
0 Kudos

Hi,

There are multiple ways to transfer data between views.

  1. Id transfer from url
  2. Using component.js , and model inside : https://answers.sap.com/questions/12258846/how-to-pass-data-from-one-view-to-another-view.html
  3. Using sap.ui.getCore().setModel() : https://answers.sap.com/questions/12385839/pass-data-from-one-view-to-another-view.html --- For this option I read some bad opinions about this solution so that it will overwrite all models on Launchpad, etc.
  4. ...

Please let me know best(practice) way to achieve this goal.

Thank you.

fikretsomay
Participant
0 Kudos

Hello,

Thank you for your answer.

https://ui5.sap.com/#/topic/5278bfd38f3940b192df0e39f2fb33b3.html

when I examine the link , it uses : "sap.ui.getCore().setModel(oModel);"

Do you also recommend this?

Accepted Solutions (1)

Accepted Solutions (1)

WouterLemaire
Active Contributor

Best practice is a combination of both, passing parameters via routes as part of the hashtags in the url and models on your component.

Always make sure that you have a unique hashtag for each page so you are always able to initialize and show the correct information on the view.

If you want to share more information besides just an ID, you can use a JSONModel for this. I would suggest to avoid creating models by using "sap.ui.getCore.setModel(model)". Instead you should define them in the manifest (this is also possible for JSONModels). This will allow you to access them in the component by just using "this.getModel("<modelname>"). In the views you can access these models with "this.getOwnerComponent().getModel("<modelname>").

Hope this answers your question.

fikretsomay
Participant
0 Kudos

Thank you for your answer.

I tried "this.getOwnerComponent().getModel("<modelname>")". I get model with oData. Thats ok.

I need to loop at result, could you please share me some piece of code?

I used ".getProperty("/setName") , and it becomes undefined at the debugger?

WouterLemaire
Active Contributor
0 Kudos

It’s not possible to access all properties directly from the odata model. You have to bind it to the view to see the data or use the read operation to actually get the data in the controller. You can also access via the bindingcontext, but again then it needs to be bound first.

For sharing data you should use json model. If you want to declare this on the manifest, you should change the type to sap.ui.model.json.JSONModel

Answers (2)

Answers (2)

former_member522344
Participant

Hi Fikret

The Best Practice

Declaring your Odatamodel or JSONModel with ID or keep it Default Model in the Descriptor File (Manifest) Then you can access it in any View .

geert-janklaps
Active Contributor

Hi,

The best practice is to use a model to store your data and access it in multiple views. Please have a look at the UI5 walkthrough regarding data binding here:

https://ui5.sap.com/#/topic/e5310932a71f42daa41f3a6143efca9c

Best regards,

Geert-Jan Klaps

fikretsomay
Participant
0 Kudos

Hello,

Thank you for your answer.

https://ui5.sap.com/#/topic/5278bfd38f3940b192df0e39f2fb33b3.html

when I examine the link , it uses : "sap.ui.getCore().setModel(oModel);"

Do you also recommend this?

geert-janklaps
Active Contributor

Hi,

This is at least the way I use to setup my models as well. Anyway this is the official documentation, which can also be considered the best practice.

Best regards,

Geert-Jan Klaps