File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes GWT and the fly likes GWT JSNI method exposure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "GWT JSNI method exposure" Watch "GWT JSNI method exposure" New topic
Author

GWT JSNI method exposure

Vincent Rogel
Greenhorn

Joined: Apr 10, 2013
Posts: 1
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

Joined: Dec 04, 2008
Posts: 54
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

Joined: Jul 26, 2007
Posts: 10248
    
    8

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?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GWT JSNI method exposure