开发者

Gwt: Share a client-side singleton across modules?

I would like to share a client singleton across GWT modules. Is this possible? If so, how?

I have several modules that need to share an EventBus (SimpleEventBus) instance. Creating a singleton in GWT Java code and having all modules inherit from the common module did not work. Each of the root modules has开发者_开发技巧 a different instance of the EventBus.

I also tried using the replace-with and create() approach documented in ClientFactory of GWT MVC and that did not work. Each module had it's own instance.

Ideas?


I found an answer on the GWT Mailing List: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/c287d3bdbc0ad458

This only works if modules are inherited and compiled into one nochache.js file. If you have several webpages each inheriting a different nochache.js it will not work.

On the other hand: If you inherit modules from each other it works.


I think that in any case it would be better to use GIN (Guice for GWT) and its @Singleton annotation. But I am not sure it will solve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜