Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vaadin JavaScript server-side component
@StyleSheet({"colorPicker.css"})
@JavaScript({"vue.js","es6-promise.auto.js", "vuex.js", "bundle.js", "vaadin-injector.js"})
public class VueComponent extends AbstractJavaScriptComponent {
private Consumer<Color> onColorChangedConsumer;
public VueComponent() {
setId("app");
addFunction("onSyncColorPicker", arguments -> {
Notification.show("Message from VUE: " + arguments.get(0).asString());
if (onColorChangedConsumer != null) {
int r = (int)arguments.getObject(0).getObject("rgba").getNumber("r");
int g = (int)arguments.getObject(0).getObject("rgba").getNumber("g");
int b = (int)arguments.getObject(0).getObject("rgba").getNumber("b");
int a = (int)arguments.getObject(0).getObject("rgba").getNumber("a");
Notification.show("Color Changed to r:" + r + ", g:" + g + ", b:" + b + ", a:" + a);
onColorChangedConsumer.accept(new Color(r, g, b, a));
}
});
}
public void onColorChanged(Consumer<Color> onColorChangedConsumer) {
this.onColorChangedConsumer = onColorChangedConsumer;
}
@Override
public VueState getState() {
return (VueState)super.getState();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment