I have a domain object that has an enum property and I want to display a dropdown list with all possible enum values in the form for this object. Imagine the following objec
In addition, if you want to separate the enum ordinal name from the string displayed in the GUI, add additional properties, for example a displayName:
public static enum State {
OPEN("open"),
IN_WORK("in work"),
FINISHED("finished");
private final String displayName;
State(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
}
And in the html file:
This will present the displayName to the user and allows you to silently change this strings later without refactoring the code. You may add more properties like th:title this way.