Tuesday, April 11, 2017

Trouble understanding JsInterop

If I have a java class and I mark it with @JsType I create a contract between Java and Javascript that I can use this class with it's given Java name in Javascript - is this correct?

package com.test.workertest.shared;


import com.google.gwt.core.shared.GWT;


import jsinterop.annotations.*;


@JsType(namespace = "test", name = "JsOpClass")
public class JsOpClass
{


   
@JsMethod
   
public void printStuff()
   
{
        GWT
.log("asdfasdf");
   
}
}


I would like to be able to create now a JsOpClass object in javascript and call printStuff() on this object but I actually don't understand where this is meant to be working. If I create for example a web worker which would create this class it reports that 

com.google.gwt.event.shared.UmbrellaException: Exception caught: (ReferenceError) : testis not defined

which makes sense because my worker.js knows nothing about GWT (would this be possible?)

And even if I try it in the GWT HTML file it doesn't seem to know about this class and I get a test is not defined error.

How do I actually call exposed classes/methods and from where is it possible? Is it only a JSNI substitute (but even then I was not able to call it from a JSNI method).

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment