Iterate through list elements from grails in jasper report

606 views Asked by At

I don't know how to render a list attribute from Grails in a jasper report

My domain class looks like this:

class Project {


String name
String projectLeader
List divisions

String toString(){
    "$name"
}


static hasMany = [divisions : Division ]
...

And the division domain class comes here

class Division {

String name
String divisionResponsible
String createDate

...

The project controller looks like this

class ProjectController {


def scaffold = true

def index = {
    redirect(action : list)
}


def createReport = {

    def projectreport = Project.getAll([params.project_id])
    chain(controller:'jasper',action:'index',model:[data:projectreport],params:params)

}

}

Displaying the data from the project domain works fine by defining and accessing the elements like this

$F{name}
$F{projectLeader}

The problem is accessing the list elements. The only working way I found was

 $F{divisions.[0].name}

or for the second element in the list

 $F{divsions.[1].name}

But this is only working if the number of list elements is everytime the same and limited.

Is there a way to iterate through the list elements, if the number of elements is not known?

Or is there a different possibility to access the list elements?

1

There are 1 answers

0
Ima Vafaei On

It doesn't need the index of list there. Use like this:

<textFieldExpression   class="java.lang.String"><![CDATA[$F{divisions.name}]]></textFieldExpression>

rather than this:

 $F{divisions.[0].name}