Right Outer Join

2 April 2010

Finding Report Templates in iReport 3.7

Filed under: iReport — Tags: , , — mdahlman @ 15:34

Where are iReport’s report Templates?

This article supersedes my article from a year ago about finding templates in iReport. I’m leaving the old article up because it’s useful if you’re still using iReport 3.1. But unless there is some odd but compelling reason to stick with the old version, you should really upgrade to iReport 3.7.

iReport uses report templates to enable a designer to develop new reports quickly. iReport ships with many prebuilt templates, and you’re free to add more templates yourself. Your self-built templates will include appropriate fonts, color schemes, logos, etc.

There are eight distinct templates that ship with iReport 3.7.  (Technically there are eighteen templates… but that counts portrait and landscape versions of essentially the same thing as different templates.) Let’s look at what the default templates give you.

Blank

This is pretty self-explanatory. Normally the blank template is not used with the report wizard. Instead it’s used to create a brand new report nearly from scratch. In fact, it works really poorly in the report wizard. It doesn’t automatically put any fields into the report. I’m not sure if this is intentional or not… it’s called “Blank”, so I guess it’s not surprising that the report is blank. If you attempt to define a report group the wizard gets stuck. This is bug 17579.

Cherry

Cherry Template

Example using the iReport Cherry template

This shows some good basic functionality. It uses the font Times New Roman; I’m not a big fan, but it’s a reasonable choice for printed reports. It incorporates some nice best practices. The formatting is all done with styles rather than applying formats to each field. The detail rows alternate background colors. This is done by putting a frame around all elements in the detail row. It’s generally better to use a frame like this rather than setting the background color for each individual field.

This example shows a simple list of Caldecott winning picture books formatted using the Cherry template.

Coffee

Coffee Template

Example using the Coffee template

This shows an interesting use of frames that go beyond the normal borders. More interestingly, it includes an image that extends off of the page. A PDF export will show the coffee stain image extending to the page borders. A HTML export will show the entire image. It extends above and to the right of the defined page size. Exporting to XHTML will clip the image on top, but it still extends out to the right.

The fonts are a mix of Times New Roman and Arial. Frankly, I find the overall impression of the fonts and colors to be ugly. But it’s still an interesting template with good ideas to draw from.

Flower

Flower Template

Example using the Flower template

There’s more cool stuff in this one. First, it uses the background band. This is an underused feature, so it’s nice to see it highlighted in this template. Even better, it’s not just a trivial background image. It includes two separate copies of the flower image so that it can be more prominent on the first page and then slide up to the top on other pages allowing more room for the data. It’s accomplished with simple Print When Expressions that test for “$V{PAGE_NUMBER} == 1” and “$V{PAGE_NUMBER} > 1”. Even better, it shows other components in the background band. In this case it’s three pie charts. Granted, there’s minimal business benefit to showing thee pie charts of random data in your reports. But the ideas may be reused for more practical solutions.

Although not important to the final report, the template also shows a nice way of adding notes to a JRXML file.

Leaf

Leaf Template

Example using the Leaf template

This is a nice clean template. No new ideas are introduced here. So I’ll take this moment to mention that all of these templates set the report language to Groovy rather than Java (hooray!), and they are all A4 size rather than letter size (hooray! or boo! depending on where you live).

Four versions are included to show different colors, but there are no differences beyond the colors.

Silhouette

Silhouette Template

Example using the Silhouette template

Is that image über-cool like an iPod ad? or is it vaguely inappropriate at work? Nevermind. The more interesting detail is the use of the background tab for a nicely formatted way of displaying the page number. “Page 1 of 18” never looked so good before.

Simple Blue

Simple Blue Template

Example using the Simple Blue template

Yuck. No reason to beat around the bush here. That’s an ugly template. None of the other templates labeled the “book_publish_year” field which I used for grouping. The other templates were better for the omission, but I guess it’s a good reminder that it’s possible to include the column name in the template. Interestingly, this template sets no fonts at all. At runtime it will just inherit the system default.

Tree

Tree Template

Example using the Tree template

This is the only remaining template that reproduces the old iReport 3.0 “Columnar” template style. I added a few fields to the SQL query compared to the samples above in order to make the idea clear. The fields in each “row” are lined up in rows rather than in columns. This is especially useful when you have large data values that don’t display well in columns.

Where are these Templates?

A year ago I had to write up a pretty detailed set of instructions to find the templates. Now in iReport 3.7 it’s as easy as you could reasonably hope. You’ll find them here:

<iReport dir>/ireport/templates

What’s Next?

Now that you’ve found the templates you can get started customizing them for your own needs. You’ll find some tips in my article Creating Report Templates in iReport.

17 April 2009

Creating Report Templates in iReport

Filed under: iReport — Tags: , — mdahlman @ 10:45

Tweaking an existing report template

Yesterday I looked at finding the existing report templates in iReport. Today I’ll modify one to create a better template.

Open classicT.jrxml in iReport 3.5. I want to make a few look-and-feel changes to get a nicer template.

  • Reformat the title to use less space
  • Change the background color in all group labels to white (transparent) and the font color to black.
  • Change the default format for the date in the Page Footer. I want it to use Java’s MEDIUM format and to be appropriate for whatever locale the report is run in:
    original: new Date()
    modified: DateFormat.getDateInstance(DateFormat.MEDIUM, $P{REPORT_LOCALE}).format( new Date() )

Save the file as NeoClassicT.jrxml into the folder Templates somewhere on my harddrive. Also copy classicT.gif to NeoClassicT.gif.

The menu Tools -> Options opens the iReport options. The tab Wizard Templates allows me to add the folder “Templates”. I could add the jrxml file directly, but I prefer to add a folder so that additional templates will be picked up automatically.

Did it work?

Choose the menu File -> New… -> Report Wizard. Go through the wizard as usual, but on Step 7 I now see both the default template “Classic” and my new template “NeoClassicT”. Hooray.

If I were truly motivated I would modify NeoClassicT.gif to show a more accurate thumbnail of the template.

The file names are important. They must be “*T.jrxml” or “*C.jrxml”. iReport decides if they are columnar or tabular templates based on these names. Likewise, it matches up the thumbnail preview image based on name matching.

16 April 2009

Finding Report Templates in iReport

Filed under: iReport — Tags: , , — mdahlman @ 10:13

Where are iReport’s report Templates?

The article has been deprecated. Don’t read it. You should refer to Finding Report Templates in iReport 3.7 instead. But I’m leaving this one up just in case you’re stuck using iReport 3.1 for some odd reason. The points made below are still true… they just are very relevant anymore.

iReport uses report templates to enable a designer to develop new reports quickly. iReport ships with two prebuilt templates, and you’re free to add more templates yourself. Your self-built templates will include appropriate fonts, color schemes, logos, etc.

It’s great that there are some sample templates to get you started, but Jaspersoft ought to include more sample templates with iReport. Rather than just complain about it… I’ll take a look at what’s involved in creating new templates.

First I need to find the existing templates. This is harder than you might expect. The templates were shipped as standalone .jrxml files back in the days of iReport Classic (versions 3.0 and earlier). But beginning with iReport 3.1 the .jrxml files are embedded directly into the iReport .jar files. iReport is now based on the NetBeans platform, so there are a lot of NetBeans related jars in a lot of directories, and none of it is familiar to me. Where are the iReport-specific files? I found them here:
<iReport dir>/ireport/modules

But where are the .jrxml template files? Browsing through a .jar file isn’t always easy. My tool of choice to find files inside it quickly is 7zip. It has an nicely unobtrusive GUI interface, but it’s the command line that I needed here:

7z l -r com-jaspersoft-ireport.jar *.jrxml
7-Zip 4.42  Copyright (c) 1999-2006 Igor Pavlov  2006-05-14
Listing archive: com-jaspersoft-ireport.jar
   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------
2009-03-27 01:03:08 .....          750          750  com/jaspersoft/ireport/Jrxml/Template.jrxml
2009-03-27 01:03:08 .....          768          768  com/jaspersoft/ireport/Jrxml/Template_groovy.jrxml
2009-03-27 01:03:08 .....         1803         1803  com/jaspersoft/ireport/designer/resources/style.jrxml
2009-03-27 01:03:08 .....         7380         7380  com/jaspersoft/ireport/designer/templates/classicC.jrxml
2009-03-27 01:03:08 .....         7454         7454  com/jaspersoft/ireport/designer/templates/classicT.jrxml
2009-03-27 01:03:08 .....          750          750  com/jaspersoft/ireport/newReport.jrxml
------------------- ----- ------------ ------------  ------------
                                 18905        18905  6 files

The interesting file in this case is classicT.jrxml. This is the prebuilt template with a tabular layout. I find it much more useful than classicC.jrxml, so I’ll base my new template on classicT.jrxml. First extract the file from the .jar. Then open it in iReport. (While I’m at it, I also extracted classicT.gif. You’ll see why later.)

At this point I have successfully found the report templates that I want. Next episode: creating new templates.

Blog at WordPress.com.