cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to pass models between views / controllers?

former_member239819
Participant
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

NagaPrakashT
Contributor

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

Answers (4)

Answers (4)

former_member239819
Participant
0 Kudos

Many thanks 🙂

NagaPrakashT
Contributor
0 Kudos

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

karthikarjun
Active Contributor
0 Kudos

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

Joseph_BERTHE
Active Contributor
0 Kudos

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

Regards,

Joseph