Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GWT JSNI method exposure

 
Vincent Rogel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding using JSNI to expose one of my GWT methods.

I have am trying to expose a method in one of my GWT classes that fires a message to other UI components.

In my application entry point I expose it with



class_a updates one of its fields, and then calls a static method from class_b.



class_b calls many other classes and static methods to process the msg


Basically, all I need to do is pass off a string and call a GWT method. The method (when called from GWT and not handwritten JS) works perfectly. I have also verified that the exposed method will fire a simple alert. I believe the problem lies in calling the other classes' methods.

I get: "(TypeError) Unable to get property 'hv' of undefined or null reference description."

Is there a way to pass off a string to the original GWT method without having to go an expose the countless other methods that it will eventually run through?
 
steve claflin
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're running into the slippery nature of "this" in JS.

Try:


I wrote this based on your code from working code I have - hopefully I transmuted it to your case correctly.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
If you are invoking static methods, why JSNI? Any particular reason, why you do not wish to invoke them from your java code?
 
steve claflin
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally haven't thought about the static vs instance methods and JSNI, although it seems that there might be uses for both to be pushed out to the window.

One situation where I've used this concept is in apps that are popups, which going to be hosted in other sites' pages and invoked via a click on one of their page elements. I have no control over their page structure, and even asking for an element with an id that I could wrap as a widget is a bit more than I'd like to do. If I can just tell them "Add onclick='xyz()' to whatever page element you want to be the trigger, that leaves them free to design the page as they see fit, using an a tag, img tag, etc. as the trigger. I can then push the function that shows the popup out to $wnd.xyz.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic