grailsjasper-reportsjasper-plugin

Using collections as parameters in Jasper from Grails


I am trying to learn how to get Jasper running from within a grails app using the jasper plugin. On the plugin directory page [ http://grails.org/plugin/jasper ] there is a fairly in-depth tutorial. Which is supposed to show you how to extend a 'racetrack' example to use the jasper plugin. The problem I'm finding is that since the 'registrations.jrxml' is not shown on the tutorial, nor does it come with the source download of the plugin -- its impossible for me to figure out how to setup a jrxml file to work with data being sent to it from grails.

Right now, my application's controller is sending an ArrayList of HashMaps back to the view, which are then turned into html tables using "g:each". It's not a simple representation of a domain, the HashMaps are constructed from several different datasources. I need to also get this data exported through Jasper to an XLS file. Right now I can send the jrxml the ArrayList as a parameter, but I am going nowhere when it comes to correlating each member of the List (a Row) to a Detail in the jrxml.

So for the simplest case say I have a controller that provides a view with an ArrayList of Strings

def index = { 
        def people = ["Donald", "Richard", "Raymond", "Samir", "Cyrus"]

        [people: people, guy: "Frank"]
    }

and a view that passes the ArrayList to Jasper as a parameter.

<g:jasperReport format="PDF" jasper="don2" name="Don Report">
    <input type="hidden" name="name" value="${guy}"/>
    <input type="hidden" name="list" value="${people}"/>
  </g:jasperReport>

What would I need to do in a jrxml to make use of the ArrayList as my datasource?

Don


Solution

  • You need JRBeanCollectionDataSource. Construct that in a controller (or in a custom tag of yours). You can't do it directly in the gsp.