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.
TwinColSelect and setting values in right column
I've read through a couple of posts on the same topic. The problem is always the same: there are no visible values in the right hand column of a TwinColSelect although getValue() does indeed return a Set with some members of the type expected.
In my case the TwinColSelect is bound to a bean which ultimately comes from JPA.
My class is called UserGroup and it implements toString(), equals() and hash().
Both the left-hand side and the right-hand side contain an underlying value which in both cases is Set<UserGroup>, as expected. The left-hand side is able to display visible values just fine, supposedly using the toString() method on UserGroup.
Couple of questions:
- Disregarding the problem with the display of values in the right-hand side why is the left-hand side able to display those exact same object types just fine? (I would expect some symmetry: either none of the sides work or both of them work).
- The real question: What am I missing that makes the values in the right-hand side invisible?
Thanks.
Peter
So I found out what the question was and I cannot find this documented anywhere ...although there's some logic to it.
Here's the correct method of populating a TwinColSelect:
- Before the beans binding you must set potential values in the left-hand column using one of TwinColSelect.addItem.. methods. You must set all potential values, disregarding if they are currently a selected value in your bean or not. Yes, the full list of potential values.
- Now do the bean binding, e.g. BeanFieldGroup.bindFieldsBuffered(userGroup, this) or whatever. This sets the right-hand column. Vaadin will automatically remove those values from the left-hand column that you set in step 1 and which are now in right-hand column.
So left-hand column first, then right-hand column.
If you do not comply with this order of events you'll get the result that the right-hand column seemingly displays nothing.
Peter