Created
August 5, 2016 21:18
-
-
Save branflake2267/3c647b8e7db15d2f6a9bcb35948132b3 to your computer and use it in GitHub Desktop.
Here is a simple GWT 2.8.0-RC1 JsInterop example showing how to use a JsOverlay and JsProperty to provide access to a String literal array written in javascript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<title>GXT Project 4.0</title> | |
<script type="text/javascript" src="MyGxtProject40/MyGxtProject40.nocache.js"></script> | |
<script> | |
var myobject = ['a', 'b', 'c']; | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gwt.core.shared.GWT; | |
import jsinterop.annotations.JsOverlay; | |
import jsinterop.annotations.JsPackage; | |
import jsinterop.annotations.JsProperty; | |
import jsinterop.annotations.JsType; | |
/** | |
* <script> | |
* var myobject = ["a", "b", "c"]; | |
* </script> | |
*/ | |
@JsType(isNative = true) | |
public class MyHelper { | |
@JsProperty(namespace = JsPackage.GLOBAL, name = "myobject") | |
private static String[] myobject; | |
@JsOverlay | |
public static String getItem(int index) { | |
//GWT.debugger(); | |
return myobject[index]; | |
} | |
@JsOverlay | |
public static void setItem(int index, String value) { | |
myobject[index] = value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gwt.core.client.EntryPoint; | |
import com.google.gwt.user.client.ui.RootPanel; | |
import com.sencha.gxt.widget.core.client.button.TextButton; | |
import com.sencha.gxt.widget.core.client.event.SelectEvent; | |
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; | |
import com.sencha.gxt.widget.core.client.info.Info; | |
public class MyHelperTest implements EntryPoint { | |
@Override | |
public void onModuleLoad() { | |
TextButton button = new TextButton("Test getting"); | |
button.addSelectHandler(new SelectHandler() { | |
@Override | |
public void onSelect(SelectEvent event) { | |
test(); | |
} | |
}); | |
RootPanel.get().add(button); | |
} | |
protected void test() { | |
String value = MyHelper.getItem(1); | |
Info.display("work?", "value=" + value); | |
MyHelper.setItem(1, "changed"); | |
value = MyHelper.getItem(1); | |
Info.display("work?", "value=" + value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, thank for the nice and simple tutorial. I have a question though.
How do you reference the JS library in your code?