tags:

views:

42

answers:

1

I want to store the exact country name using g:countrySelect. Example Germany instead of DEU. It is the value in the drop down menu. The drop down text is Germany but when it saves it to the database it changes back to the country code. Sorry if I am somewhat naive but I have been searching for almost 3 hours for solutions and it isn't well documented at the grails website. I could opt for any alternative even ajax. Just to have an easy way to display a list of countries and will be able to store the REAL NAME of the country NOT country code. Thank you!

+2  A: 

You can convert from an ISO3 country code to the country name using this function

def getCountryName(String countryCode) {
  Locale.availableLocales.find{it.ISO3Country == countryCode}.displayCountry
}

// Test
println getCountryName('DEU')  // prints 'Germany'

If you want to do this within a GSP, it would be best to make this available as a TagLib.

Don