Dropdowns with Enums in Grails

GSP:

<g:select name="personType"
      from="${es.xoubin.labgrails.PersonType?.values()}"
      keys="${es.xoubin.labgrails.PersonType.values()*.code()}"
      value="${personInstance?.personType}"
      valueMessagePrefix="person.enum.personType" />

Domain:

 enum PersonType {
 EMPLOYEE('E'), USER('U'), MANAGER('M'), PUBLIC('P')
 private final String code
 PersonType(String code) {
 this.code = code
 }
 public String code() {
 return code
 }
 }
 class Person {
 [...]
 String personType
 [...]
 }

messages:

person.enum.personType.E=Employee!!
person.enum.personType.U=An user
person.enum.personType.M=Eficient manager
person.enum.personType.P=Anonymous public
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s