I want to create a report for my domain class instances but not all, just the ones user selected in the GSP table (selecting checkboxes). On my report I will also have some logic - few conditionals, some calculations etc. I would also have to get some additional data from database. How do I do this? Should I get values of selected checkboxes in cotroller and pass it to jasper cotroller? Something like this:
GSP:
<g:each in="${books}" var="bookInstance">
<td> <g:checkBox name="book_${bookInstance.id}"/> </td>
</g:each>
Action:
def bookReport = {
def bookList = []
params.each {
if(it.key.startsWith("book_")){
bookList.add((it.key - "book_") as Long)
}
}
def bookCriteria = Book.createCriteria()
def books = bookCriteria.list {
'in'('id',bookList)
}
chain(controller:'jasper', data:books, action:'index', params:params)
}
I used iReport for report creation. I've tried creating report without SQL query and parameters. My logic was that if I pass a map of domain instances to jasper controller as I did in the example above I dont need to specify data source in report. But I get an empty report.
I also tried seting the report datasource to my database and report query to this: select * from book where $X{IN,id,books}. In that case, no matter what I select report is created for all book instances.
Have you tried...
...while leaving the SQL string empty in your .jrxml?