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.
Viritin ElementCollectionField with enum
How to use ElementCollectionField with jpa elementCollection of enum?
I have this field within my jpa entity
@ElementCollection(targetClass = MyEnumType.class)
@CollectionTable(name = "MyTable", joinColumns = @JoinColumn(name = "columnId", nullable = false))
@Column(name = "myField", nullable = false)
@Enumerated(EnumType.STRING)
private Set<MyEnumType> enumTypes;
and this in my form
private ElementCollectionField<MyEnumType> enumType;
public static class MyTypeRow {
EnumSelect<MyEnumType> type = new EnumSelect<MyEnumType>();
}
@Override
protected Component createContent() {
FormLayout layout = new FormLayout();
enumType = new ElementCollectionField<>(MyEnumType.class, MyTypeRow.class)
.withCaption("Types")
.withEditorInstantiator(() -> {
MyTypeRow row = new MyTypeRow();
row.type.setOptions(MyEnumType.values());
return row;
}
);
}
I got a java.lang.InstantiationException. I guess that enum are not supported in ElementCollectionField.
Is there another way to achieve this?
Got another way using the SubSetSelector<MyEnum>.
Solved.
Yep, EnumSelect is a single select component, SubSetSelector is for multiselection. By extending that for some enum magic, it might be possible to create EnumMultiSelect, which wouldn't require you to explicitly define the options.
cheers,
matti