Skip to Content

Share model between controllers - global model vs eventbus

Feb 04, 2017 at 01:48 AM


avatar image


i have a controller/view that displays a form for the user to make selections.

the selections are stored in a json model.

i need to pass the selections model to another view/controller where other stuff is done.

i could create a global json model and access it from both views or pass the model from one view to the other.

any suggestions as to which way is better?



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

2 Answers

Best Answer
Boghyon Hoffmann Feb 05, 2017 at 08:33 AM

Depending on your business case, there are several approaches when it comes to setting models. Generally, You'd set your model on your ...

  • Component if your model should be available across all of your views that are descendants of that component. Models defined in the app descriptor (manifest.json) are set automatically on the component and will stay there until the end of the component's lifecycle.
  • View if the data is not needed elsewhere. The model is available during the view's lifecycle only.
  • Core if your app is not Component-based (e.g. for a small demo on jsbin) since core models won't be automatically propagated to the Component as described here.

In your case, if you have only two views that need the selection data, you could set the model to the first view and then pass it on to the second view on navigation. Something like this:

<App navigate=".onNavigate" />
onNavigate: function(event) { // minimal example
    const targetView = event.getParameter("to");
    if (targetView.byId("/*idOfThatPageIWant*/")) {
        const sourceView = event.getParameter("from");
        const modelName = "/*thatModelName*/";
        targetView.setModel(sourceView.getModel(modelName), modelName);
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thank you Boghyon Hoffman for your reply.

Jun Wu Feb 04, 2017 at 02:10 AM

global model

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Jun Wu,

Any reason why global model is preferred over the other? I am just trying to understand the rationale behind your thoughts.

Lets say if we have bunch of pages in our app, with global model approach, we tend to provide access to unwanted views (which in a way is polluting the global space)

Your thoughts could clarify better.


Murali L


global model within the component


Hi Jun Wu,

are you saying the model should be created in Component.js so that the views that 'hang off' the component can access the model.




yes..............just like the context in the component controller(web dynpro)


Thank you Jun Wu.