Grails Reporting: Getting The Most Out of Jasperreports and Dynamicjasper in Grails by Keith Cochran
Grails Reporting: Getting The Most Out of Jasperreports and Dynamicjasper in Grails by Keith Cochran
80%
Getting the most out of JasperReports and DynamicJasper in Grails by Keith Cochran
Wednesday, May 13, 2009 1
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
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.
Dynamic Jasper
Create reports in a cong le instead
of .jrxml or .jasper format
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/
Using iReport
10
11
13
Parameters
Fill in the report name and hit Next Make sure you select the correct data
source
14
Query Designer
Drag a table to right Select elds (Order counts!) Right-click elds for options
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
16
18
Fields
Select the elds to display Use arrow keys to move them to the right.
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.
20
Select a layout
Pick either a columnar or tabular layout Hit next Select nish on the last screen
21
Save the report (saves as .jrxml format) Select Preview to compile and view the
results
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.
24
25
28
Grails Domains
For the demo, I up a ReportParameter
class ReportParameter { Report report String name String dataType String value Date dateValue }
29
DEMO
31
Dynamic Jasper
Drink Price ($) Sales ($1000s)
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
33
Ways to use DJ
Quickly use it in a URL Entity Based Conguration Named Reports Conguration
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)
36
37
Use the static reportable Youve already seen columns dened You can also dene title, dataSource,
grouping, etc.
39
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, ???
41
objects so you can obtain info from the session and pass in variables
report: the name of the report closure reportFormat: PDF, XML, etc. PDF is the
default
43
Demo
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