Search code examples
grailsgroovygsp

groovy display list<list> with each tag


Need to display list in table format.

var dispList = [["a","b","c"],["d","e","f"]]

Tried using nested <g:each> tag, but no success. Any suggestions ?

format-

<table>
  <tr>
   <td>a</td>
   <td>b</td>
   <td>c</td>
 <tr>
 <tr>
   <td>c</td>
   <td>d</td>
   <td>e</td>
 <tr>
</table>

Solution

  • Nested <g:each> loops do work, but I've generally found I have to use the var attribute rather than relying on the default "it" variable name. If you have an variable called dispList in your GSP model then you can do

    <table>
      <g:each in="${dispList}" var="row">
        <tr>
          <g:each in="${row}" var="val">
            <td>${val}</td>
          </g:each>
        </tr>
      </g:each>
    </table>