Skip to Content

Is it possible to pass models between views / controllers?

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Sep 11, 2017 at 12:44 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 08, 2017 at 09:08 PM

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

    Regards,

    Joseph

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 09, 2017 at 03:46 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 12, 2017 at 04:07 PM

    Many thanks :)

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 11, 2017 at 12:43 PM

    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

    Add comment
    10|10000 characters needed characters exceeded