Sample usage of @JavaScriptBody annotation. Preprocessing classes and adding a Js/Java interoperability test
3 import net.java.html.json.ComputedProperty;
4 import net.java.html.json.Function;
5 import net.java.html.json.Model;
6 import net.java.html.json.Property;
8 /** Model annotation generates class Data with
9 * one message property, boolean property and read only words property
11 @Model(className = "Data", properties = {
12 @Property(name = "message", type = String.class),
13 @Property(name = "on", type = boolean.class)
15 final class DataModel {
16 @ComputedProperty static java.util.List<String> words(String message) {
17 String[] arr = new String[6];
18 String[] words = message == null ? new String[0] : message.split(" ", 6);
19 for (int i = 0; i < 6; i++) {
20 arr[i] = words.length > i ? words[i] : "!";
22 return java.util.Arrays.asList(arr);
25 @Function static void turnOn(Data model) {
29 @Function static void turnOff(final Data model) {
30 confirmByUser("Really turn off?", new Runnable() {
38 /** Shows direct interaction with JavaScript */
39 @net.java.html.js.JavaScriptBody(
40 args = { "msg", "callback" },
42 body = "alert(msg); callback.@java.lang.Runnable::run()();"
44 static native void confirmByUser(String msg, Runnable callback);