cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass values from List Report page to object page without sap.ui.getCore().?

0 Kudos
572

I am developing a List Report application , where I have a requirement to pass values from List Report page to object page .

I did it by set a global JSON Model

ListReportExt.Controller.js:

sap.ui.getCore().setModel(oSearchValueModel,"SearchValueModel");

ObjectPageExt.Controller.js:

this.SearchValue = sap.ui.getCore().getModel("SearchValueModel").getData();

It works in local environment, but when I push it, the Jenkins build failed.

Fiori Architectural Guidelines said, "Model should not be set or read from sap.ui.getCore() as we are in a shared environment!"

How can I solve it? Is there other method to repleace sap.ui.getCore() define a global variable?

Thanks,

Bingyang

View Entire Topic
sergei-u-niq
Active Contributor

You could use a model that is bound to the component.

//assume “this” is controller 

this.getOwnerComponent().set/getModel
0 Kudos

Thank you.

I tried it, but it didn't work.

I need setModel in List Report, and getModel in Object Page. The two "this" are different controllers, so ObjectPageExt.Controller.js can not get model that set by ListReportExt.Controller.js.

If I define the Model in Manifest.json, I can setModel in ListReportExt.Controller.js , but getModel is empty in ObjectPageExt.Controller.js .

Regards,

Bingyang

vinibar
Participant

That's why you should set the model to the component, as sergei.haller.u-niq has suggested

sergei-u-niq
Active Contributor
0 Kudos

yes. Assuming both views belong to same application, "this.getOwnerComponent()" will give you the same component. so get/setmodel will work in both controllers.

0 Kudos

Hi Haller,

Should I declare the Model in component.js or manifest.json?

this.getOwnerComponent().getModel("MyModel") returned undefined in ObjectPageExt.Controller.js.

My app followed ABAP RESTful Application Programming Model.

Thanks,
Bingyang

sergei-u-niq
Active Contributor
0 Kudos

Hi Bingyang, if getModel(modelName) returns undefined, the model isnt there (yet)

from technical point of view, there are many ways to declare it. To stay on the same line as your original code, you could just run in ListReportExt.Controller.js:

this.getOwnerComponent().setModel(oSearchValueModel,"SearchValueModel");

on in Component.js

this.setModel(oSearchValueModel,"SearchValueModel");

or (best practice)

  1. declare your JSON Model with name "SearchValueModel" in manifest.json
  2. add data to it in ListReportExt.controller.js:
// do not replace the model !! replace/add data
this.getView().getModel("SearchValueModel").setData({"foo": "bar"}) // replaces all data with the given object
this.getView().getModel("SearchValueModel").setProperty("/cool", true)

3. get data from it in ObjectPage.controller.js

this.getView().getModel("SearchValueModel").getData() // will return {foo:"bar", cool: true}
this.getView().getModel("SearchValueModel").getProperty("/foo") // will return "bar"

Best Regards, Sergei

0 Kudos

Hi Sergei,

Thank you very much!

setData instead of setModel solved my problem.

Best Reagrds,

Bingyang