I have TwinColSelect within a FieldGroup and bound it to a BeanItem Property. To display all available values I also set the ContainerDataSource for the TwinColSelect. The Problem is that I only get the values from the data source and nothing is preselected. I have already tried to preselect some values via the setValue method of the TwinColSelect but it didn’t work.
Initialization of TwinColSelect(roleSelect):
roleSelect.setRequired(true);
roleSelect.setRequiredError("Es muss mindestens eine Rolle ausgewählt sein.");
roleSelect.setContainerDataSource(container);
roleSelect.setMultiSelect(true);
roleSelect.setWidth(400, Unit.PIXELS);
I assume no converters are explicitly selected as you don’t write about them.
The container data source (possible values) is working but you have problems with pre-selection based on the field used as property data source or with explicitly setting the value.
Is the field “authorities” of a suitable type - for TwinColSelect, a Set of the item ID type? For setting the value from code, other collections might work but for TwinColSelect to update “authorities”, the field should be compatible with a Set, and it happens easily that you put something else than item IDs in the set. Converters can help there.
If you set the value of the field (rather than the property data source) you need to set the value after binding the field.
One final possible explanation: maybe your ID types don’t have suitable equals()/hashCode() implementations and multiple equivalent instances end up in the system e.g. via a persistence framework.