How to list childrens recursively in a GSP page?

grails, gsp, recursion, tags

Solution

You could put the recursive part into a GSP-template and then call it recursively, e.g.:

`index.gsp`: Assuming `rootMedias` is passed into the view

<g:each in="${rootMedias}" var="media">
    <g:render template="step" model="${[media: media]}" />
</g:each>

`_step.gsp`

<ul>
    <g:each in="${media.children}" var="child">
    <li>
        ${child.name}
        <g:render template="step" model="${[media: child]}" />
    </li>
    </g:each>
</ul>

Problem

i have a Media Domain ``` def Media { String name static belongsTo = [parent:Media] static hasMany = [children:Media] } ``` In the show.gsp page i want to list all my root Media (that haven't parent) into an ul list an their children and their children recursively in another ul lists. I have used the Tag for the first list but i don't know how to do this recursively for the children. So have you an idea of how to do this ? Thanks.

Original source