You could set the object state in a ValueChangeListener, eg.
select.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
Object values = select.getValue();
if (values instanceof Set) {
// Multiple selected values returned as a Set
List<String> list = new ArrayList<String>((Set) values);
attribute.setSelectedValues(list.toArray(new String[list
.size()]));
} else if (values != null) {
// If only one value is selected it will be a String
attribute.setSelectedValues(new String[] { values
.toString() });
} else {
attribute.setSelectedValues(null);
}
}
});
Is this the standard and/or best manner of capturing the selected values? The reason I ask is I have been using BeanItem for most properties and it seems to work quite well. For a Select, I had expected to be able to use assign it to some manner of method that takes a String (or maybe Object
) of selected items. This seems like it would be a common use case.
Our R&D guys will correct me if I’m wrong, but as far as I know there is no standard for autowiring such an attribute set to a Select. You are right that it is a common need, and a simple pattern implementation in the library could cover >90% of the cases. If you write a feature request ticket about it, maybe it’ll appear in 6.3