Skip to content

Instantly share code, notes, and snippets.

@branflake2267
Created August 23, 2016 22:19
Show Gist options
  • Save branflake2267/57fa08114e4496f9f3c3a832190c3302 to your computer and use it in GitHub Desktop.
Save branflake2267/57fa08114e4496f9f3c3a832190c3302 to your computer and use it in GitHub Desktop.
A simple example using JsInterop to export for third party api use.
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sencha.gwt.jsinterop.examples.processor.Example;
import jsinterop.annotations.JsType;
/**
* Don't forget to add -generateJsInteropExports to the compiler arguments for use in production.
*/
@Example(name = "JsInterop Export Example", category = "GWT", icon = "java")
public class JsInteropExportExample implements EntryPoint, IsWidget {
@JsType(namespace = "myapi")
public static class User {
public String firstName;
public String lastName;
public final String getFullName() {
return firstName + " " + lastName;
}
}
private HTML widget;
@Override
public void onModuleLoad() {
RootPanel.get().add(this);
}
@Override
public Widget asWidget() {
if (widget == null) {
User person = new User();
person.firstName = "Brandon";
person.lastName = "Donnelson";
widget = new HTML("FullName=" + person.firstName);
}
return widget;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment