Reputation: 421
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?
Upvotes: 0
Views: 597
Reputation: 967
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}
Upvotes: 1