简体   繁体   English

Vaadin精灵插件事件火灾两次

[英]Vaadin wizard addon event fire twice

I am using Vaadin wizard addon and I have a problem with the following case: 我正在使用Vaadin向导插件,我遇到以下情况的问题:

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) 但是,如果用户想要转到上一步,我不小心在同一事件中添加了一个Button click监听器(这是我的假设。我调试了程序并看到如果用户转到上一页,那么事件火两次)

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. 另外,我不知道在哪里删除它们,因为在用户移动到Vaadin向导的下一页之前我找不到执行的函数。

I am following this example: 我跟着这个例子:

https://github.com/tehapo/WizardsForVaadin/tree/master/wizards-for-vaadin-demo/src/main/java/org/vaadin/teemu/wizards 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? 有没有删除所有ClickListeners的方法?

If it exists, where should I add that functionality? 如果存在,我应该在哪里添加该功能?

Also, I am using ListDataProvider and NativeSelect components too. 此外,我也使用ListDataProviderNativeSelect组件。

NativeSelect has HasValue.ValueChangeListener<String> listener and in the default implementation, I Could not find a method such that I can use this: NativeSelect有HasValue.ValueChangeListener<String>监听器,在默认实现中,我找不到一个方法,以便我可以使用它:

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 我在public Component getContent() {}方法中设置click侦听器

In Vaadin 8 you need to use the Registration interface to remove Listeners. 在Vaadin 8中,您需要使用注册界面删除监听器。

When you add a Listener it will return the Registration: 添加监听器时,它将返回注册:

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

And then to remove it: 然后删除它:

registration.remove();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM