1

I have two GWT modules with its own entry point, ModuleA and ModuleB. I am using Window.assign() to move from ModuleA to ModuleB. One Variable value is set in ModuleA. How to access the same value from ModuleB?

Thanks in advance.

2 Answers2

1

I have written a couple of answers which could help you to deal with this.

Since you cannot share pure java between two compiled modules: GWT: How to share a java Object (ie: EventBus) between two modules, I suggest to export methods using jsni: How to communicate two modules in GWT. But I would use gwt-exporter or gwt-query to avoid writing js by hand which normally is a source of mistakes: Calling GWT Java function from JavaScript

Note, that these solutions only work in the case both modules are loaded in the same html.

If you want to pass a value to a different page downloading the actual, you can append those values to the new url and read it in the second application:

  // Module A
  Window.Location.assign("module_B.html?msg=whatever");

  // Module B
  String msg = Window.Location.getParameter("msg");
Community
  • 1
  • 1
Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
0

IMO the best way would be to implement the observer/observable pattern in pure JavaScript in your host page, and use JSNI in your application to register handlers/fire events.

Olivier Tonglet
  • 3,312
  • 24
  • 40
  • Other than using observer patterns, is there any other way to achieve this? I am looking for a way to save values in ModuleA so that I can access the same from ModuleB. – Nandini Murthy Sep 13 '13 at 09:19
  • Well, you can use JSNI, without implementing the pattern. There is no standard built-in GWT mechanism to do that because you have multiple way to deplay your module and there is no guarantee they will be on the same page (i.e. if you use iframes). Other threads can be found on the web and they come to the same conclusion. Sorry I can't help you more than I did ! – Olivier Tonglet Sep 13 '13 at 09:57
  • 1
    You're welcome. If it works out, I'd be glad to hear about it ! – Olivier Tonglet Sep 13 '13 at 10:27