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.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 1 month ago
Binding an OptionGroup to List
Hello Guys,
We use an OptionGroup to let a User select one or more Items. The OptionGroup has a Binder to a HashSet. Now every time we try to commit, we get the following Exceptions:
com.vaadin.data.fieldgroup.FieldGroup$CommitException: Commit failed
com.vaadin.data.util.converter.Converter$ConversionException: Could not convert value to Set
We already tried to write a Converter for it, but this doesnt work either:
public class RollenConverter implements Converter<Object, Set<Rolle>> {
private BeanContainer<Integer, Rolle> container;
private final static Set<Rolle> MODEL_TYPE_INSTANCE = new HashSet<Rolle>();
private OptionGroup opg;
public RollenConverter(AbstractSelect field) {
this.container = (BeanContainer<Integer, Rolle>) field.getContainerDataSource();
opg=(OptionGroup) field;
}
@Override
public Set<Rolle> convertToModel(Object value, Class<? extends Set<Rolle>> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
Set<Rolle> models = new HashSet<Rolle>();
if (container.size() > 0) {
for (Object itemId : ((HashSet<Object>) value)) {
if (container.containsId(itemId)) {
models.add(container.getItem(itemId).getBean());
}
}
}
return models;
}
@Override
public Object convertToPresentation(Set<Rolle> value, Class<? extends Object> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
for(Rolle r:value){
if(opg.containsId(r.getId())){
opg.select(r.getId());
}
}
return value;
}
@Override
public Class<Set<Rolle>> getModelType() {
return (Class<Set<Rolle>>) MODEL_TYPE_INSTANCE.getClass();
}
@Override
public Class<Object> getPresentationType() {
return Object.class;
}
}
Has someone an idea whats wrong? Please help
Last updated on
You cannot reply to this thread.