Hey everyone,
I'm currently researching ways to implement communication between two separate GWT modules within a host page. I know it's generally possible using JSNI, exporting of Java functions (via gwt-exporter or manually) and overlay types (JavascriptObject and so on).
However, due to project circumstances I need to pass java objects between those modules that do NOT extend JavascriptObject. The reason is that I cannot introduce a GWT dependency into an otherwise non-GWT code base which is used for one of these modules. So far I only added classes around the actual code base that implement GWT-specific behaviour (mainly an EntryPoint class) and delegate to the underlying functionality.
By testing I found out that I can pass custom java objects between my modules if I make sure that the necessary methods for them are existing at the receiving side (I checked this by looking at and stepping through the generated javascript code.)
In my small sample application I forced the GWT-compiler to generate specific methods of a class by creating a dummy instance and calling its methods in onModuleLoad(). As soon as those were generated to javascript I could pass an object of the same type from another module and use its methods.
If I didn't create these dummies and "dummy"-use their methods the javascript code was not generated and it ended up calling null.nullMethod(). I believe this is due to the pruning phase during optimization steps of the compile process.
Long story, short question: Can I disable this pruning step for selected classes (or even methods) of my java classes?
Or is there another way to force the compiler to generate these methods to javascript?
With kind regards,
Erik
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/hNtg34rQf1sJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Object
of the correct type that must have originated in Java code" ...Thank you for your thoughts, Manuel!
I've tested this some more yesterday and found out that using gwt-exporter isn't enough. The compiler will still prune any methods and class that doesn't seem to be used even if it was exported to JS.
The real problem here is that the compiler has strict rules about where "original" java objects can be obtained.
If the only way to get a reference to a java object of type X is an external call from JS (or another gwt module via jsni), the compiler will always remove this type and all it's methods. The JSNI documentation here is the key for me: "JavaObject
of the correct type that must have originated in Java code" ...
Following this description I've added an exported dummy method which returns a static object of type X. That way it's possible to have a reference to a java object in javascript and pass it back to java. However, I don't actually use this method. Instead I use a jsni call from my second gwt module which transfers a different object of the same type to my receiver module. Et voilà, it works!
Erik
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/qWOp3_Gm88oJ.