Grails
  1. Grails
  2. GRAILS-8518

Map iteration with g:each tag as it was in Grails 1.x.x

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0 final
    • Fix Version/s: 2.0.2, 2.1-RC1
    • Component/s: TagLib
    • Labels:
      None

      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="$

      {mapEntry.key}

      " />
      <g:set var="value" value="$

      {mapEntry.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.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Lari Hotari
            Reporter:
            Antony Jones
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development