Reputation: 8587
I was using this same snippet under 2.3.7 yesterday which worked fine, but under Grails 2.4.0 it returns only the first object.
Just wondering if it is something dodge on my end or if indeed in 2.4.0 that the first line is returned on output. If you comment out the countries <<
line it prints it all to console, with that line enabled it just returns 1 record.
def listCountries() {
def countries = []
def locale = Locale.getAvailableLocales().find { availableLocale ->
def lang=availableLocale?.getLanguage()?.toString()
def country=availableLocale.getCountry().toString() ?: lang
println "---"+lang+"---"+country
countries << "${lang},${country}"
}
render countries
}
Upvotes: 1
Views: 112
Reputation: 50245
There are many things to look at. First of all countries
is a list instead of a map. :)
The logic in listCountries
can be drilled down as below:
def listCountries() {
render Locale.availableLocales?.collect {
"${it.language.toString()},${it.country.toString()}"
}
}
find
will only return the first result when a condition is satisfied or evaluates to Groovy True, hence it prints only once in your case.
Upvotes: 2