On Tuesday, April 11, 2017 at 10:43:06 AM UTC+2, Philipp wrote:
>
> 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?
>

First, you have to pass -generateJsInteropExports to GWT (compiler, 
codeserver, devmode), to actually export the JsType to JavaScript.
Then, from the context the GWT app (*.nocache.js) was loaded in, you should 
be able to do '(new test.JsOpClass()).printStuff()', *after* your GWT app 
has been loaded/started (once onModuleLoad has been called)
 

> Is it only a JSNI substitute
>

Yes.
 

> (but even then I was not able to call it from a JSNI method).
>

var o = new $wnd.test.JsOpClass();
o.printStuff();

…but maybe all you miss is the -generateJsInteropExports?

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to