0% found this document useful (0 votes)
67 views46 pages

Grails Reporting: Getting The Most Out of Jasperreports and Dynamicjasper in Grails by Keith Cochran

This document summarizes a presentation about reporting tools for Grails applications. It discusses Jasper Reports for creating reports with iReport and passing parameters, and Dynamic Jasper for quickly generating reports from configuration files instead of iReport. The presentation demonstrates how to use these tools to build reports in Grails by connecting to domain models, passing parameters, and exporting reports in different formats.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views46 pages

Grails Reporting: Getting The Most Out of Jasperreports and Dynamicjasper in Grails by Keith Cochran

This document summarizes a presentation about reporting tools for Grails applications. It discusses Jasper Reports for creating reports with iReport and passing parameters, and Dynamic Jasper for quickly generating reports from configuration files instead of iReport. The presentation demonstrates how to use these tools to build reports in Grails by connecting to domain models, passing parameters, and exporting reports in different formats.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Grails Reporting

Jasper Dynamic Jasper


20%

80%

Getting the most out of JasperReports and DynamicJasper in Grails by Keith Cochran
Wednesday, May 13, 2009 1

Where to get this


www.cochran-software.com downloads Contains presentation and sample
Grails app

Wednesday, May 13, 2009

Objectives
Today well learn about Jasper Reports Creating reports with iReport Passing parameters to reports Using Dynamic Jasper
Wednesday, May 13, 2009 3

What is it?
Jasper Reports is Open-source reporting tool for Java Flexible Report Layout Supply data in multiple ways Variety of export formats
Wednesday, May 13, 2009 4

System Setup

Wednesday, May 13, 2009

For Demo
JasperReports DynamicJasper iReport Example Grails App: DrinkMaster
Wednesday, May 13, 2009 6

Jasper Reports
Open Source Java Reporting Library grails install-plugin jasper Current version: 0.9.5 Can export reports in plain text, Excel,
PDF, RTF, HTML, XML, and CSV.

Can use either .jrxml or .jasper le


Wednesday, May 13, 2009 7

Dynamic Jasper
Create reports in a cong le instead
of .jrxml or .jasper format

grails install-plugin dynamic-jasper Current version: 0.5

Wednesday, May 13, 2009

iReport
Download iReport 3.5.0 for your platform Mac: http://mac.softpedia.com/get/
Developer-Tools/iReport.shtml ireport/

Others: http://sourceforge.net/projects/

Wednesday, May 13, 2009

Using iReport

Wednesday, May 13, 2009

10

3 Steps to Create Reports


Set up and use a data connection Use report wizard to create a rst cut Build, Run, Tweak, Retest cycle

Wednesday, May 13, 2009

11

How To Setup Data Connections


Wednesday, May 13, 2009 12

Use Report Wizard

File -> New -> Report Wizard

Wednesday, May 13, 2009

13

Parameters
Fill in the report name and hit Next Make sure you select the correct data
source

Select design query to open the Query


Designer.

Wednesday, May 13, 2009

14

Query Designer

Drag a table to right Select elds (Order counts!) Right-click elds for options

Wednesday, May 13, 2009

15

Where Clause

Right click on the where clause to add a condition Example: Enter drink.id in the top window Use =, enter ingredient.drink_id in the bottom

Wednesday, May 13, 2009

16

Grouping and Ordering


Under Select Right click a parameter Select either add to group-by for grouping add to order-by for ordering
Wednesday, May 13, 2009 17

What the Final Query Looks Like...


SELECT drink.`name` AS drink_name, ingredient.`description` AS ingredient_description FROM `drink` drink, `ingredient` ingredient WHERE drink.id = ingredient.drink_id GROUP BY ingredient_description ORDER BY drink.`name` ASC

Wednesday, May 13, 2009

18

Fields

Select the elds to display Use arrow keys to move them to the right.

Wednesday, May 13, 2009

19

Group By

Select the column you want to group the report by. This can be different than the Query. This allows grouping on the report.

Wednesday, May 13, 2009

20

Select a layout

Pick either a columnar or tabular layout Hit next Select nish on the last screen

Wednesday, May 13, 2009

21

Edit and Run


Edit the report look in the designer if
desired

Save the report (saves as .jrxml format) Select Preview to compile and view the
results

After compile, .jasper le is created and


saved as well
Wednesday, May 13, 2009 22

Jasper Format
When you create a new report, its in jrxml
format.

After compiling it, there is a .jasper format The compiled .jasper format runs faster
than .jrxml.

.jrxml les need to be compiled eventually


for use by Jasper.
Wednesday, May 13, 2009 23

DEMO: Upload Report and Run in Grails


Show a Demo of how to write the

controller so you can upload the report.

Wednesday, May 13, 2009

24

Passing Parameters to Reports

Wednesday, May 13, 2009

25

Modify the Report


Return to the report in iReport Right-click on Parameters in the report
inspector and add a parameter

Name the parameter something meaningful


(i.e. nameongredient) and use the appropriate data type (java.lang.String)

I use String type for Dates as well!


Wednesday, May 13, 2009 26

Modify the Query


Open the query in the report wizard again
and add the following to the where clause: $P{nameongredient}

where ingredient.name like The parameter is case sensitive!


Wednesday, May 13, 2009 27

Passing Parameters from Grails


In your Grails app: use hidden tags in the
form when calling Jasper.
<g:jasperReport ...> <input type=hidden name=blah value=blah/> </g:jasperReport>

Wednesday, May 13, 2009

28

Grails Domains
For the demo, I up a ReportParameter
class ReportParameter { Report report String name String dataType String value Date dateValue }

domain in Grails to hold report parameters

Wednesday, May 13, 2009

29

In the GSP: Loop thru Parameters...


<g:jasperReport jasper="${report.id + '/' + report?.leName}" format="${report?.formats()}" name=" " delimiter=" "> <g:each in="${report?.reportParameters}" status="i" var="parameter"> <g:if test="${parameter?.dataType == 'Date'}"> <input type="hidden" name="${parameter?.name}" value="<g:formatDate format="yyyy-MM-dd" date="${parameter?.dateValue}"/>"> </g:if> <g:else> <input type="hidden" name="${parameter?.name}" value="${parameter?.value}"> </g:else> </g:each> </g:jasperReport>

Important! Dates should be passed as strings.


Wednesday, May 13, 2009 30

DEMO

Show code on how to include parameters


in call to Jasper.

Wednesday, May 13, 2009

31

Dynamic Jasper
Drink Price ($) Sales ($1000s)

100 75 50 2007 2008 2009 2010


Wednesday, May 13, 2009 32

25 0

What is it?
Create a simple report in a cong le
instead of using iReport

Version 0.5 as of this demo Use this to create dynamic reports that
dont need the complexity of iReport

Wednesday, May 13, 2009

33

Ways to use DJ
Quickly use it in a URL Entity Based Conguration Named Reports Conguration

Wednesday, May 13, 2009

34

URL Method
Add this to your domain class you want to
report on: etc.]]

def static reportable = [columns: [name, Append to URL: djReport/?entity=myEntity Report of all instances of this entity
Wednesday, May 13, 2009 35

Parameters
entity: the domain class to report on reportColumns: list of columns to use
(overrides columns listed in domain)

reportFormat: sets the output type

Wednesday, May 13, 2009

36

Tweak Report Style


Define the following in DynamicJasperConfig.groovy useFullPageWidth: defines if the report will use the full page width page: page size and orientation intPattern: the pattern to use with integer numbers floatPattern: the pattern to use with floating point numbers datePattern: the pattern to use with dates titleStyle: the style to use for the report title subtitleStyle: the style to use for the report subtitle headerStyle: the style to use for the columns header detailStyle: the style to use for the data cells

Wednesday, May 13, 2009

37

Entity Based Reports


Dene report parameters inside the
domain class

Use the static reportable Youve already seen columns dened You can also dene title, dataSource,
grouping, etc.

See Plugin page for more cong options


Wednesday, May 13, 2009 38

Named Reports Conguration


In the conf directory, make a le
DynamicJasperCong.groovy
dynamicJasper { someReport { <parameters go here> } }

Inside that cong le, format is:

Wednesday, May 13, 2009

39

Dynamic Jasper Cong File


This le is loaded at run-time, and changes
are not picked up while running.

Provide a report name and a closure


enclosing the report parameters

Wednesday, May 13, 2009

40

Parameters

Entity: the table to report on Title: title of the report Columns: array of columns to include Patterns: use for date formats, etc. ColumnTitles: change the display of columns FileName: the name of the le to create GroupColumn: column to group by, if needed GroupFooterColumn: ?? GroupOperation: one of SUM, ???

Wednesday, May 13, 2009

41

Final Parameter... dataSource: This is where you can modify


the query and gain complexity

Contains session and parameter

objects so you can obtain info from the session and pass in variables

Return data set out of the closure


Wednesday, May 13, 2009 42

On the URL, these are the parameters to


pass in:

report: the name of the report closure reportFormat: PDF, XML, etc. PDF is the
default

Wednesday, May 13, 2009

43

Demo

Named Report Building and Demo.

Wednesday, May 13, 2009

44

Summary
Today we learned about iReport to create reports Jasper Reports and passing parameters Dynamic Jasper for quick reports
Wednesday, May 13, 2009 45

Questions?
Question Obscurity Answer Hilarity
100 75 50 25 More Even More Off the Chart
Wednesday, May 13, 2009 46

Less

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy