Huskilq1
Huskilq1

Reputation: 13

Vaadin wizard addon event fire twice

I am using Vaadin wizard addon and I have a problem with the following case:

When the user only presses forward/next step, there is no problem. However, if the user wants to go to the previous step, I am accidentally adding a Button click listener to the same event(That is my assumption. I have debugged the program and saw that if the user goes to the previous page, the event fires twice)

I have tried to remove the event listener before going to the next page, however, I could not find a method to remove all of the event listeners once. Also, I don't know where to remove them, since I could not find a function executed before the user is moved to the next page in Vaadin wizard.

I am following this example:

https://github.com/tehapo/WizardsForVaadin/tree/master/wizards-for-vaadin-demo/src/main/java/org/vaadin/teemu/wizards

Is there a method to remove all of the ClickListeners?

If it exists, where should I add that functionality?

Also, I am using ListDataProvider and NativeSelect components too.

NativeSelect has HasValue.ValueChangeListener<String> listener and in the default implementation, I Could not find a method such that I can use this:

NativeSelect<String> select = new NativeSelect<>("List");

select.addValueChangeListener(new HasValue.ValueChangeListener<String>() {
   // some overwritten valuechange method
}

select.removeValueChangeListener(); // This does not exist

I am setting the click listener in the public Component getContent() {} method

Upvotes: 1

Views: 262

Answers (1)

Jay
Jay

Reputation: 1678

In Vaadin 8 you need to use the Registration interface to remove Listeners.

When you add a Listener it will return the Registration:

final Registration registration = select.addValueChangeListener(this::doSomething);

And then to remove it:

registration.remove();

Upvotes: 3

Related Questions