Unable to access exported JsType from JavaScript

56 views
Skip to first unread message

Andrea Spadaccini

unread,
Jun 19, 2016, 2:37:05 PM6/19/16
to GWT Users
Hi everyone,
I am trying to port my CPU simulator from Java to Javascript, and I am using GWT for it. Thanks for the awesome work!

I'd like to just expose a single Java object to JS, and then build the UI using HTML/CSS/<JS framework du jour>. To do so, I think I need to use JsInterop, right?

I am trying to do so, without success.

My code (https://github.com/lupino3/edumips64/blob/jsinterop/src/main/java/org/edumips64/client/WebUi.java) compiles to JS and I can see the code running and producing output in the Chrome console. However, I can't find a way to access the WebUI.runAndGetRegisters() method from the Chrome console. Once that works, I can set up a better interface between JS and Java, but first I'd like to be able to execute one single method.

Given my current use of JsType, under what name should I be able to run the WebUI.runAndGetRegisters() method?

Thanks in advance,
Andrea

Jens

unread,
Jun 19, 2016, 3:33:29 PM6/19/16
to GWT Users
Did you forgot to add -generateJsInteropExports to the compiler parameters?

-- J.

Thomas Broyer

unread,
Jun 19, 2016, 5:54:48 PM6/19/16
to GWT Users
Looking at your code, the class would be available at "blah.WebUI", but you'd have to create a new instance before your can call your method, and given how you initialize it you'd have to call onModuleLoad before that.
Maybe if you make your method and all the fields 'static' that'd work; either that or move the initialization in the class constructor (and maybe use another class as the EntryPoint to avoid a double initialization).

Andrea Spadaccini

unread,
Jun 20, 2016, 3:34:46 AM6/20/16
to GWT Users
Hi,
 
Did you forgot to add -generateJsInteropExports to the compiler parameters?

I set it for both devmode and production code: https://github.com/lupino3/edumips64/blob/jsinterop/build.xml#L104

Is it set in the right way?

Thanks!
Andrea

Andrea Spadaccini

unread,
Jun 20, 2016, 3:37:41 AM6/20/16
to GWT Users
Hi,
 
Looking at your code, the class would be available at "blah.WebUI", but you'd have to create a new instance before your can call your method, and given how you initialize it you'd have to call onModuleLoad before that.
Maybe if you make your method and all the fields 'static' that'd work; either that or move the initialization in the class constructor (and maybe use another class as the EntryPoint to avoid a double initialization).

Thanks for the pointer, it works! I can do the following in JS:

x = new blah.WebUI();
x.onModuleLoad();
x.runAndGetRegisters();

I don't know how I missed it. :)

Again, thanks a lot for the pointer.

Cheers,
Andrea
Reply all
Reply to author
Forward
0 new messages