0

the problem is quite simple yet maybe not resolvable? Atleast for me :/

Situation: Let's say I have a dynamic Page System where the Server provides additional copies of self containing GWT Modules. Meaning a main GWT instance on the client side is supposed to manage the new incoming GWT Scripts, which are simply added by the main instance itself using Tags. Now the main GWT instance needs to communicate with the newly created script instances in the most easiest (GWT internally) way possible.

So what is out of the question: Writing stupid JSNI Wrappers on both sides, if not absolutely required.

Soltuions I came up with were: Make a module both use, including a common interface, example:

package com.whatever.interfaces;

public interface Communication {
  void showMessage(String message);
}

So both would now inherit this module and know of the definition. The main client would now load the dynamic JS and register an implementation of Communication and the dynamic one would go and use it. I tried storing references on $wnd and on elements using setPropertyObject. On $wnd they are null, which maybe/probably related to the the GWT Iframing? For the property on the RootPanel element for example, ClassCastException would be raised.

Is there any good way to encounter this? Another idea I have is using JSNI for calling the interface as an implementation on the bridge module, but I'm not sure if this a good way.

Your help is appreciated, thanks.

EDIT: Well I have pretty much come to the conclusion that this is not possible whatsoever. Even though you might have used same interfaces somewhere, they will be very own instantiations of it, for different modules compiled, even if using the same module as a common ground. The approach using JSNI certainly is somewhat possible, but not without mapping all attributes to real JS Objects and remapping them back. Meaning you can't pass complex Java Objects around like you probably would be used to. My conclusion would be, using CodeGenerators you could build the JSNI Wrappers automatically and the remappers, for both modules, but this is too much of a hassle for me.

I'm still open if someone comes up with a better idea, but I just want to provide some inside on my findings, so others can benefit of my wasted time ;)

3 Answers3

0

A while ago, I created a simple prototype implementation to share Object instances to other GWT modules. You can find the code on https://code.google.com/p/gwt-plug/. And yes, as you described, it's a problem to transfer Java objects. As far as I remember, you can only transfer primitive values (int, float, ...), Strings and JavaScriptObjects. But JavaScriptObjects are a good possibility

Steffen Schäfer
  • 1,126
  • 9
  • 11
0

As you already found out communicating between separately compiled GWT modules is somewhat of a challenge since everything is obfuscated. It is possible though through javascript, JSNI, JSO's and JSON.

  1. You can use JSNI to create communication hooks through javascript directly on the $wnd object. Sort of an event bus approach would work.

  2. You can use JSON to pass around complex objects.

  3. You can use JSO's (JavaScript Overlays) to consume and manipulate the JSON in each of the disperate modules.

  4. Putting all that together you would end up with a mini-framework library module that you would share between the various GWT modules you want to have communicate with each other. They would each inherit the common framework module and compile in their own obfuscated form but since they are using javascript and JSON as a common language they won't have to worry about the obfuscation.

Make sense?

xsee
  • 1,173
  • 1
  • 9
  • 12
0

As explained in the xsee's answer, you can create a hook from GWT using JSNI

In order to do this, take a look to very useful project http://code.google.com/p/gwt-exporter/

bsorrentino
  • 1,413
  • 11
  • 19