4

This works as expected in a GSP-page:

<td>${Foo.findAllByBar(bar)}</td>

But when adding a collect statement the code breaks ..

<td>${Foo.findAllByBar(bar).collect { it.name }}</td>

with

Error 500: Could not parse script [...gsp]: startup failed,
     ...: 129: expecting '}', found ')'
     @ line 129, column 196. 1 error`.

I was under the impression that any valid Groovy code could be placed in a GString ${ ... } and being correctly evaluated/expanded. What am I missing?

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
knorv
  • 49,059
  • 74
  • 210
  • 294

2 Answers2

6

Alternatively, you can use the spread operator:

<td>${Foo.findAllByBar(bar)*.name}</td>
Matt Lachman
  • 4,541
  • 3
  • 30
  • 40
4

The GSP parser doesn't like } within the ${...} block. Try this one:

<%= Foo.findAllByBar(bar).collect { it.name } %>
Siegfried Puchbauer
  • 6,539
  • 34
  • 24