Tuesday, September 15, 2015

Re: JsInterop hello world

Thank's Jens, your help is much appreciated. For now I will definitely go for a no-renaming approach.

It must be something with the way I run my code server.

I still get the same error, and when I inspect the generated javascript in my browser, it still has the obfuscated format. 
The generated javascript in the war file however, looks much better.

Maybe I just need to get the configuration of my gwt-maven-plugin right.


Den tirsdag den 15. september 2015 kl. 23.32.36 UTC+2 skrev Jens:
Ok just played a bit and its like the following:

@JsExport // value attribute is ignored here, probably because it acts as a shortcut to apply @JsExport to any static member
@JsType // required so you also have exported instance members (your sayHello method) and not just static members
@JsNamespace("poc") // the default namespace, should probably go in a package-info.java file
public class JsHello {
public String sayHello(String name) {
return "Hello " + name;

With the above you can do

var hello = new poc.JsHello(); hello.sayHello("World");

If you want to rename JsHello to Hello you do

public class JsHello {
@JsExport("poc.Hello") // replaces any @JsNamespace default value so you need to add namespace here
public JsHello() {}
public String sayHello(String name) {
return "Hello " + name;

I would try to avoid renaming, as you must repeat the namespace in @JsExport. Just name your classes correctly and stick with the first example with @JsNamespace in a package-info.java file.

-- J.

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