Setting up nested style templates in iReport and JasperReports

Style templates are a great way to abstract style definitions that are shared across a report out to an external file. This makes them easier to maintain and understand of course, but once your report library grows you will likely consider setting up one or a small number of shared style templates, probably with particular styles per report in sub templates.

The master template file, let’s call it shared_styles.jrtx, might look something like this:

<?xml version="1.0"?>
<!DOCTYPE jasperTemplate
 PUBLIC "-//JasperReports//DTD Template//EN"
 "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">
<jasperTemplate>
 <style name="Default" isDefault="true" fontName="Circus"/>
 <style name="distinct" forecolor="#A0A0A0" backcolor="#FFFFFF" \
vAlign="Middle" fontSize="13" isBold="true" isItalic="true"/>
 </style> 
</jasperTemplate>

And let’s imagine a single sub-template, sprocket_styles.jrtx:

<?xml version="1.0"?>
<!DOCTYPE jasperTemplate
 PUBLIC "-//JasperReports//DTD Template//EN"
 "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">
<jasperTemplate>
 <template><![CDATA[shared_styles.jrtx]]></template> 
 <style name="quiet" backcolor="#FFFFCC" fontSize="8" \
  forecolor="#CCCCCC"/>
</jasperTemplate>

For this to work, you need to add the directory containing these two jrtx files to the classpath that is passed to jasperreports.

You can also add this directory to the classpath in iReport (Preferences), and both will load the styles appropriately. This approach lets you keep your styles separate and easy to work with, and it even minimizes the change required for each report to incorporate style templates: you only need to add a style reference to the appropriate sub-template for the report, and it will load the shared one.

Be Sociable, Share!

Post to Twitter Post to Delicious Post to Digg Post to Reddit

This entry was posted in iReport, JasperReports, Reporting. Bookmark the permalink.

5 Responses to Setting up nested style templates in iReport and JasperReports

  1. przęsła ogrodzeniowe, says:

    Przęsła ogrodzeniowe są cudownie prostym rozwiązaniem jeśli musimy zastosować zakup odpowiedniego dla Nas sposobu grodzeń, jest idealny zarówno na terenie prywatnych
    posesji, jak i przy zwykłym ogrodzeniu plantacji oraz terenów strzeżonych.
    Montażsiatki leśnej daje zabezpieczenie przez sarnami lub zającami, które obgryzają nasz drzewka
    ozdobne. Główną cechą chzakterystyczną jest mnogość zastosowań.
    Zaletą takiego rozwiąznia, jest też jego wydajność oraz prosty montarz.
    Polecam.

  2. Panele ogrodzeniowe są idealnym rozwiązaniem jeśli musimy zastosować montarz odpowiedniego dla Nas sposobu grodzeń, jest bardzo wydajny zarówno na terenie publicznych terenów, ale również przy zwyczajnym ogrodzeniu domu
    oraz całych gospodarstw. Wybórsiatki leśnej zapewnia osłonę przez zwierzętami leśnymi,
    które zbliżają się do naszych domostw i pól uprawnych.

    Główną cechą chzakterystyczną jest duża
    funkcjonalność. Istotą takiego rozwiąznia, jest też jego wydajność oraz .
    Polecam.

  3. SEO Organics says:

    Neat blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really make my blog jump out.
    Please let me know where you got your theme. Thanks

  4. Jeśli macie ochotę to zalecam użytkować kabiny
    prysznicowe. Jest to bardzo kożystna alternatywa, która pozwala uczynić z łazienki Twoje miejsce, gdzie można ukoić skołatane nerwy oraz co
    najistotniejsze nie zużywając dużo wody wziąć kąpiel.
    Zastąpienie wnny na rzecz kabiny prysznicowej pociąga za
    sobą widoczne różnice w rachunkach. Używając przysznica zużywamy mniej wody i prądu.
    Oprócz tego, kabina prysznicowa jest dużo bardziej wygodniejszy w
    eksploatowaniu najbardziej dla ludzi starszych.

  5. Ich denke, dass viele Menschen davon profitieren können.
    Hallo Leute, hab gerade bei Google Alerts von diesem
    Blog erfahren und finde ihn überaus informativ. Danke.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>