title: Beginning jasperReport/iReport with Grails
body: <p>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:</p>
  
  <p>GSP:</p>
  
  <pre><code> &lt;g:each in="${books}" var="bookInstance"&gt;
          &lt;td&gt; &lt;g:checkBox name="book_${bookInstance.id}"/&gt; &lt;/td&gt;
   &lt;/g:each&gt;
  </code></pre>
  
  <p>Action:</p>
  
  <pre><code>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)
  }
  </code></pre>
  
  <p>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. </p>
  
  <p>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.</p>