2

I need a way to share information between modules - not only between components in the same module -. I have common data to share between the different moduleContext.

-I tried using the application context (moduleContext.getParentContext().setSettings() or getSettings(), but each module context has a different moduleContext.getParentContext().

-I also tried creating a singleton object for the application, but even in this case the singleton data of the first module (landing page) are not available for the other modules.

-The third thing I tried is to pass data via notifications (notify / listen), with the same results.

Does anyone knows how to solve this problem?

Marcos

1 Answers1

1

If you want to keep relationship between the module tree, it is necessary that you create your module hierarchy by calling:

parentContext.loadChildContexts(moduleContexts);

When this is done, that method ensures the 'event mediator' of child contexts is set to the exact same 'mediator' instance of the parent context. Then an event occurring at any of the modules will be notified to all the contexts in the same module tress.

It is the same for settings as well. When 'loadChildContexts' method is used, the settings of the parent context are 'copied' to child context settings.

If it still doesn't work for you, can you share your code to me? I may help you to find where the issue is.

Hasith
  • 1,749
  • 20
  • 26
  • Hi Hasith, Thanks for your help. In fact the issue isn't exactly between modules, but between the "modules" loaded in the domController (like Menu, Language, etc) and the component loaded in the module. I put a "User" component in the DomController. When the user login, I have to share the user information with the modules. I have to work in this way because part of the site is open, without necessary login. – user2023899 Jan 31 '13 at 23:53
  • Also, the user component must show the username after the login, so I mandatory have to be able to communicate between the components in the DomController and the components in the UrlController – user2023899 Feb 01 '13 at 00:03
  • Login is a tricky use case to handle with SPA model. This is why you will find almost all SPA apps around handles login with a page refresh. Although you can get this to work with BPJS events, is it possible for you to do a page refresh just after the login, such that all components can reload themselves allowing them to retrieve new logged in status from the server session? – Hasith Feb 01 '13 at 18:59