How do you embed g: each tag in gsp?

Suppose I have the following classes

class Genre {
    static hasMany=[author:Author]
}

class Author{

    static hasMany=[books:Books]
}


class Books{
       Author author 
}

How do I start typing this in gsp using g: each tag?

+5
source share
1 answer

If you want to display all the books by the author, you might have something like

<g:each var="author" in="${Author.list()}">
    <p>Author: ${author.fullName}</p>
    <ul>
    <g:each var="book" in="${author.books}">
        <li>${book.title}</li>
    </g:each>
    </ul>
</g:each>

Hooray!

+9
source

All Articles