Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
CheckBox Example in Book of Vaadin is looping ?
I'm working through the Book of Vaadin, 4th Edition, to get a understanding if Vaadin is appropriate for us.
In Chapter 5.12, Page 100, there is an example of two CheckBoxes togging each other crosswise.
I tried this, also to learn about debugging via Eclipse (Juno).
On contrast to other breakpoints from other examples the breakpoints on CheckBox Events did not trigger.
After some time I came to the finding that these two Checkboxes modifying each other create a loop, such producing a burst of events which can't be handled by the system.
Is my interpretation right ? If yes, should I file a bug to improve the book ?
CheckBox is by default non-immediate and hence the event wasn't fired. If you add checkbox(1/2).setImmediate(true), then the events will be fired. You are correct, that the code in the book will theoretically result in a loop, but in practice this loop does not occur and here's why: Let's consider the initial state where checkbox1 has the value false and the cb2 has the value true. Now if you click on cb1, it's value will be change to true and an event is sent. The event listener will now try to copy cb1's state to cb2 by calling cb2.setValue(true). But because cb2's value is already true, its value doesn't change and hence it won't send a ValueChangeEvent - thus preventing the loop.
Ah, I see..
I added setImmediate(true) and it works now. Thank You.
For vaadin starters it's a little bit tricky that code which is mandatory for a working example is not printed in the book. I have experienced this several times. For experienced vaadin developers surely those things are nobrainers, but you loose time to get along the learning curve.
Focussing on the core stuff in the book and providing the full code elsewhere to recheck in case of problems would be beneficial.