Skip to Content
0

Is it possible to pass models between views / controllers?

Sep 08, 2017 at 08:00 PM

64

avatar image

I have 2 separate views, each with their own controller.

First view is the first "Part" of a survey, second view is the rest.

I have a model view setup for each, but is is possible to pass the details of the First page's model to use in the second?

I know you can include parameters in routing but they're large text fields in this case.

The other option I have is to save the details in the back-end and only pass over a reference number of the created model as a parameter.

Any other thoughts?

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

5 Answers

Best Answer
Naga Prakash Sep 11, 2017 at 12:44 PM
1

To exchange the entire data model between views you can set the model to Component instead of global core

From best practice, please do not use global core.

Below code snippet may help you

// Set the log model to the Component
var logModel = new sap.ui.model.json.JSONModel();
logModel.setData(data);
this.getOwnerComponent().setModel(logModel, "jsonLogs");

In other view

var oModel = this.getOwnerComponent().getModel("jsonLogs");
oModel.getData();

Thanks,

NP

Share
10 |10000 characters needed characters left characters exceeded
Joseph BERTHE Sep 08, 2017 at 09:08 PM
0

Why you do not use a global model (in the manifest) ?

Regards,

Joseph

Share
10 |10000 characters needed characters left characters exceeded
A K Sep 09, 2017 at 03:46 AM
0

Got your point, I will give my suggestion to you.

1) use global model. (sap.ui.getCore().setModel(<YOUR JSON MODEL>, "REFERENCENAME"))

2) use the reference name in your second page. like( new sap.m.Text({ text: "{REFERENCENAME>/Property}"}))

Regards,

AK

Share
10 |10000 characters needed characters left characters exceeded
Adam Harkus Sep 12, 2017 at 04:07 PM
0

Many thanks :)

Share
10 |10000 characters needed characters left characters exceeded
Naga Prakash Sep 11, 2017 at 12:43 PM
0

To exchange the entire data model between views you can set the model to Component instead of global core

From best practice, please do not use global core.

Below code snippet may help you

// Set the log model to the Component
var logModel = new sap.ui.model.json.JSONModel();
logModel.setData(data);
this.getOwnerComponent().setModel(logModel, "jsonLogs");

In other view

var oModel = this.getOwnerComponent().getModel("jsonLogs");
oModel.getData();

Thanks,

NP

Share
10 |10000 characters needed characters left characters exceeded