Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you nest g:each tags in gsp?

Tags:

grails

gsp

Assume I have the following classes

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

class Author{

    static hasMany=[books:Books]
}


class Books{
       Author author 
}

How do I go about printing this in the gsp using g:each tag?

like image 747
Neoryder Avatar asked Mar 18 '10 20:03

Neoryder


1 Answers

If you want to display all books by author you could 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>

Cheers!

like image 140
lunohodov Avatar answered Sep 21 '22 20:09

lunohodov