JS callback to Vaadin component

Viewed 72

I have a JS component (SigPlot) that I need to read click values from. I have instantiated SigPlot inside of a VerticalLayout, where I also instantiate a DIV to pass to the SigPlot constructor. I am not sure if this is a valid way, but it works. Now I need to read CLICKS but I am having troubles finding correct way to do this. Can someone pass some words of wisdom?

In my constructor for my VIEW, it use addAttachListener to start my JS code using.

div.addAttachListener(e->{
    e.getUI().getPage().executeJs("myInit($0)",div);
});

How can I register a click listener to this?

Regards

1 Answers

As long as it's just a regular DOM event listener, then something like this should work:

div.getElement().addEventListener("click", event -> Notification.show("Clicked"));

If you need to do something on a more granular level, then your might want to expose callbacks as @ClientCallable and then use executeJs to run some short JavaScript snippets to set up listeners that delegate to those methods.

Related