on 2021 May 13 10:03 AM
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
You could use a model that is bound to the component.
//assume “this” is controller
this.getOwnerComponent().set/getModel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
That's why you should set the model to the component, as sergei.haller.u-niq has suggested
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)
// 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
User | Count |
---|---|
71 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.