I have a class:
class User {
Set<Foo> foos = []
}
where Foo
is an enum:
class Foo { A, B, C, D}
I have a controller action with a parameter of type User
def someAction = {User user ->
// impl omitted
}
I've created a multi-select in a GSP
<g:select name="foos" multiple="true" from="${Foo.values()}"/>
But when I submit the form the selected values do not get bound to the foos
property of the User
command object. What am I doing wrong?
http://www.grails.org/TipsAndTricks
Enum usage
If you want to use a Enum with a "value" String attribute (a pretty common idiom) in a element, try this:
enum Rating {
G("G"),PG("PG"),PG13("PG-13"),R("R"),NC17("NC-17"),NR("Not Rated")
final String value
Rating(String value) { this.value = value }
String toString() { value }
String getKey() { name() }
}
Then add optionKey="key" to your tag. Credit: Gregg Bolinger
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With