Why doesn't .collect () work in the next GString?

This works as expected on the GSP page:

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

But when you add a collection operator, the code breaks.

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

from

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

I got the impression that any valid Groovy code could be placed in GString ${ ... } and properly priced / extended. What am I missing?

+4
source share
2 answers

The GSP parser does not like } in the ${...} block. Try the following:

 <%= Foo.findAllByBar(bar).collect { it.name } %> 
+4
source

Alternatively, you can use the operator:

 <td>${Foo.findAllByBar(bar)*.name}</td> 
+6
source

All Articles