[ This Blog Was Moved To : http://www.diknows.com ]
I am currently working at a Project that should be internationalized ( Arabic – English ). I am still developing it. I needed list of countries to be internationalized and I wanted it to be in the domain constraints (inList). I may later put the data in the database, but for the time being; I’m putting the data in the domain class.
Here is what I did
I put the data in the model like this :
class Address {
static constraints = {
gpsLng(nullable:true)
gpsLat(nullable:true)
address()
city()
state()
country(inList:['afghanistan',
'albania',
'algeria',
'american_samoa',
...
'zaire',
'zambia'])
dateCreated(nullable:true)
lastUpdated(nullable:true)
}
Date dateCreated
Date lastUpdated
String gpsLng
String gpsLat
String address
String city
String state
String country
String toString(){
"$address"
}
}
And at the properties files I did the internationalization like this
address.country.afghanistan=Afghanistan address.country.albania=Albania address.country.algeria=Algeria address.country.american_samoa=American Samoa ...
And in the view .. I did this ( I’m using beanField plugin too )
<bean:select beanName="address" property="country"
name="country" id="country"
from="${address.constraints.country.inList}" valueMessagePrefix="address.country" value="${fieldValue(bean:address,field:'country')}" optionValue="${message(code:it)}" />
And this is it .. The valueMessagePrefix is used to indicate the prefix to be added to the key in inList list and get the value from the properties files. optionValue is what user see ( Label ).
When the form is submitted, the value in the inList will be passed back to the controller.
Hope I was helpful to someone.


