My Grails application has a large number of enums that look like this:
public enum Rating {
BEST(\"be\"), GOOD(\"go\"), AVERAGE(\"av\"), BAD(\"ba\"), WORST(\
So the default Databinding binds on the Enum name and not a separately defined property of the Enum. You can either create your own PropertyEditor as you have mentioned or do a work-around similar to this:
class MyCommand {
String ratingId
Rating getRating() {
return Rating.getEnumFromId(this.ratingId)
}
static constraints = {
ratingId(validator:{val, obj -> Rating.getEnumFromId(val) != null })
}
}