Tuesday, September 15, 2015

Re: JsInterop hello world

That didn't seem to make much of a difference, the generated javascript still have the wrong identifiers, and the error message is the same :(

I wonder if there is something wrong with my build, it looks to me as if the annotations are ignored.
I know that I run gwt 2.8, as I did a lambda to verify that, and I can see that the code server is started with '-XjsInteropMode, JS'.

Could I simplify it further, by removing the namespace or something?

Thanks ...

/Brian

Den tirsdag den 15. september 2015 kl. 14.46.01 UTC+2 skrev Brian Pedersen:
So I am doing my first baby-steps in JsInterop, exposing a Java class to javascript, and I can't seem to figure out what I am doing wrong.

My java class looks like this:
@JsExport("poc.Hello")
public class JsHello  {
 
public String sayHello(String name) {
   
return "Hello " + name;
 
}
}

And the javascript in my host page like this:
var obj = new poc.Hello();
alert(obj.sayHello("there"));

My browser complains about 'poc' being undefined:
Uncaught ReferenceError: poc is not defined

Which is understandable, when looking at the implementation generated:
_.sayHello_0_g$ = function Cyb_g$(name_0_g$){
 
return 'Hello ' + name_0_g$;
}
;
var Ldk_bitwerk_client_JsHello_2_classLit_0_g$ = cDb_g$('dk.bitwerk.client', 'JsHello', 428, Ljava_lang_Object_2_classLit_0_g$);

I have tried all sorts of things, such using the real package/class name inside @JsExport, omiting the package/class name inside @JsExport and adding @JsType to the class declaration.
I have also tried annotating a constructor instead of the class.

I am running gwt-2.8.0-snapshot with jsInteropMode=JS, and I have committed the code here: https://github.com/bitwerk/jspoc

Any help will be much appreciated ...

/Brian

--
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 http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment