Archive | September, 2011

Grails select valueMessagePrefix

21 Sep

In several days ago, i just know there is valueMessagePrefix attribute of g:select. It’s very useful in some cases, for example, we want to display day of week (from Mon to Sun); this code will do.

in gsp:

<g:select name="dayOfWeek" from="${['1', '2', '3', '4','5','6','7']}" valueMessagePrefix="label.dayofweek" />

in messages.properties :

label.dayofweek.1=Mon
label.dayofweek.2=Tue
label.dayofweek.3=Wed
label.dayofweek.4=Thu
label.dayofweek.5=Fri
label.dayofweek.6=Sat
label.dayofweek.7=Sun