Originally posted by Gareth Millward:
However I just want to display the first available object in the for each not all of them.
There are a couple of things you might need to know here. Firstly, that if if you declare a "[]" in Grails, it creates a Set by default. So if you are concerned about the order in which your images are in, you'll want to declare it like this:
This is the reason you were getting the exception, because there is no way to access a Set element with the subscript operator [0], because the Groovy Set object has no getAt() method.
Secondly, if you only want the first element of the List, you don't need to loop through with <g:each/>. If it is a List, you can just do this:
If the collection is a Set, however, and you really don't care which image you use, you can cast it to a List and use the subscript operator. This is essentially a random image from the collection.
Hope that helps you out.
[ October 07, 2008: Message edited by: Matthew Taylor ]