Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Javascript event gets fired N times
I want to open a new browser tab via BrowserWindowOpener. As for this to work I have to .extend() the opener to a component that must be clicable and clicked but my "triggering" element is not a button, I ended using a trick which consists in a hidden Vaddin button that is "clicked" via Javascript when the user interacts with my regular "interactable" Vaadin component. I assign an id to my "fake", hidden Vaadin button and add the js code to fire a .click() on it after I do the opener.extend(myFakeButton).
The problem is that the 1st time I do the action the method kind of works as expected. It opens a new browser tab with the proper content. But the 2nd time I do the same action, 2 tabs are opened, and 3 the third time, and so on.
The way I use for adding the code that simulates the click is simply via the JavaScript.getCurrent.execute() method:
JavaScript.getCurrent().execute("document.getElementById('myFakebuttonId').click();");
There's no matter if I put this in the middle of my java code or if I wrap it inside a JavaScript.getCurrent.addFunction(whatever) block. It's like if the js code was being added everytime again and again everytime I do the action that triggers its execution. Or like if the target element was being added again each time.
I also tried to add my Javascript as a "component" like stated here: https://vaadin.com/docs/-/part/framework/gwt/gwt-javascript.html
But, unfortunately, I came to a dead when I was trying to "inform" my java code that an element was clicked from javascript.
Ok, again I'm answering myself.
What I was doing was creating the BrowserWindowOpener, and applying its .extend() method, several times, that is, dynamically, calling to the method that does it each time I was applying the click.
Now I understand that I must create the opener and extending it just one time and maybe change its contents later.