views:

74

answers:

2

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?

+1  A: 

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

<%= Foo.findAllByBar(bar).collect { it.name } %>
Siegfried Puchbauer
Thanks! Using <%= ... %> solved the problem. Is this a bug or is it by design?
knorv
this is by design.
Siegfried Puchbauer
+3  A: 

Alternatively, you can use the spread operator:

<td>${Foo.findAllByBar(bar)*.name}</td>
Matt Lachman