Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use jasperreports subreports with grails jasper plugin?
    primarykey
    data
    text
    <p>I would like to use subreports with grails jasper plugins, I followed the manual at this url (<a href="http://www.grails.org/plugin/jasper" rel="nofollow noreferrer">http://www.grails.org/plugin/jasper</a>). Here is my code :</p> <p><strong>Domain Book :</strong> </p> <pre><code>class Book { static belongsTo = Library Library library String title String author String publisher String category static constraints={ title() author() publisher() category() } } </code></pre> <p><strong>Domain Library :</strong></p> <pre><code>class Library { static hasMany = [ books : Book ] String name String adresse Date dateMaturity static constraints = { } String toString() { return name } } </code></pre> <p><strong>In my BookController, I have :</strong> </p> <pre><code>def createReport = { def books = Book.list() chain(controller:'jasper',action:'index',model:[data:books],params:params) } </code></pre> <p><strong>In my LibraryController, I have :</strong></p> <pre><code>def createReport = { def library = Library.list() chain(controller:'jasper',action:'index',model:[data:library],params:params) } </code></pre> <p><strong>My jasper part is :</strong></p> <p>I have a SubReport file : books.jasper (get a list of books).<br> Also a MasterReport : library.jasper (get a list of library).</p> <p>In my MasterReport(library), I added subreport, I would like, for each library, show list of books it contains ; here is my library code :</p> <pre><code>&lt;parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"&gt; ... &lt;field name="books" class="java.util.Collection"/&gt; ... &lt;subreport isUsingCache="true"&gt; &lt;reportElement x="0" y="25" width="437" height="100"/&gt; &lt;dataSourceExpression&gt;&lt;![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{books})]]&gt;&lt;/dataSourceExpression&gt; &lt;subreportExpression class="java.lang.String"&gt;&lt;![CDATA[$P{SUBREPORT_DIR} + "books.jasper"]]&gt; &lt;/subreportExpression&gt; &lt;/subreport&gt; </code></pre> <p>And I have this error :</p> <p><strong>Error 500:</strong> Executing action [index] of controller [JasperController] in plugin [jasper] caused exception: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{books})<br> <strong>Exception Message:</strong> failed to lazily initialize a collection of role: bookshelf.Library.books, no session or session was closed </p> <p>Thank you for help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload