Details
Description
In Grails 1.x.x it was possible to iterate a map in a clean, intuitive way with the g:each tag:
<g:each in="$
{myMap}" var="key, value">...
</g:each>
This is no longer possible due to some internal reworking of the taglibs, and the following stacktrace is shown:
Line | Method
->> 13 | runTask in /grails-app/views/versions/index.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by MultipleCompilationErrorsException: startup failed:
home_ant_Projects_nice_map_iteration_grails_app_views_versions_index_gsp: 25: unexpected token: project @ line 25, column 6.
for( project, version in evaluate('versions', 13, it) { return versions } ) {
^
1 error
The workaround is not very clean:
<g:each in="${myMap}
" var="mapEntry">
<g:set var="key" value="$
" />
<g:set var="value" value="$
" />
...
</g:each>
My suggestion is to adapt the new taglib to check for maps as the 'in' variable, and if a comma is found in the 'var' string, assign key+value to the two variable names.
Example application attached.
-
Hide
- nice-map-iteration-bug-report-19122011.zip
- 19/Dec/11 10:41 AM
- 22 kB
- Antony Jones
-
- grails-app/.../ApplicationResources.groovy 0.1 kB
- grails-app/conf/BootStrap.groovy 0.1 kB
- grails-app/conf/BuildConfig.groovy 2 kB
- grails-app/conf/Config.groovy 4 kB
- grails-app/conf/DataSource.groovy 1 kB
- grails-app/conf/UrlMappings.groovy 0.2 kB
- grails-app/conf/spring/resources.groovy 0.0 kB
- grails-app/.../VersionsController.groovy 0.2 kB
- grails-app/i18n/messages.properties 3 kB
- grails-app/.../messages_cs_CZ.properties 3 kB
- grails-app/i18n/messages_da.properties 3 kB
- grails-app/i18n/messages_de.properties 4 kB
- grails-app/i18n/messages_es.properties 3 kB
- grails-app/i18n/messages_fr.properties 2 kB
- grails-app/i18n/messages_it.properties 2 kB
- grails-app/i18n/messages_ja.properties 4 kB
- grails-app/i18n/messages_nl.properties 3 kB
- grails-app/.../messages_pt_BR.properties 3 kB
- grails-app/.../messages_pt_PT.properties 3 kB
- grails-app/i18n/messages_ru.properties 4 kB
- grails-app/i18n/messages_sv.properties 3 kB
- grails-app/i18n/messages_th.properties 6 kB
- grails-app/.../messages_zh_CN.properties 2 kB
- grails-app/views/error.gsp 0.3 kB
- grails-app/views/index.gsp 3 kB
- grails-app/views/layouts/main.gsp 2 kB
- grails-app/views/versions/index.gsp 0.4 kB
- test/unit/.../VersionsControllerTests.groovy 0.3 kB
- application.properties 0.1 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
There are no comments yet on this issue.