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.
TextField and Label wont work with enum
Hi my Bean has a "Status" field, it is a Java enum.
public class InvitoNoSoa implements Invito {
....
@NotNull
private Status status;
....
}
public enum Status {
NEW, WORKING, CLOSED;
}
binding this field to a TextField and to Label both they works when reading value from Bean, but they both throws an
Caused by: com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: my.packege.Status.<init>(java.lang.String)
when they tries to update status when bean status changes.
Even I tried to us Status enum with String label into constructsr like this
public enum Status {
NEW("Nuovo"), WORKING("In Lavorazione"), CLOSED("Chiuso");
final String label;
Status(final String label) {
this.label = label;
}
@Override
public String toString() {
return label;
}
}
but unfortunetly neither it works.
So is there a workaround or it is impossible to use properly enum in Vaadin forms?
Regards
Pietro Marrone: Hi my Bean has a "Status" field, it is a Java enum.
binding this field to a TextField and to Label both they works when reading value from Bean, but they both throws an
Caused by: com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: my.packege.Status.<init>(java.lang.String)
when they tries to update status when bean status changes.
Even I tried to us Status enum with String label into constructsr like this
Java enum constructors can only be called within the enum declaration.
One option would be to use a PropertyFormatter as a wrapper for the property data source of the field. It can convert between a String representation and your enum, using valueOf() and toString(). Note that the UI may return string values that are not legal values for the enum.
This is not really ideal, though - you need to wrap the property somewhere.