KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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("wo") final String id private RateType(String id) { this.id = id } static public RateType getEnumFromId(String value) { values().find {it.id == value } } } If I have a command object such as this: class MyCommand { Rating rating } I would like to (for example) automatically convert a request parameter with value "wo" to Rating.WORST. The procedure for defining custom converters is described here (in the context of converting Strings to Dates). Although this procedure works fine, I don't want to have to create a class implementing PropertyEditorSupport for each of my enums. Is there a better alternative?
Tags (comma-separated)
Save Edits
Cancel