DynamicJasper


To add common auto text expressions in header and footer such as “Page X of Y”, “Created on 07/23/2007”, etc. Just use the DynamicReportBuilder like this:

For page counter

drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y,
AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT);

For creation time

drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON,
AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT,
AutoText.PATTERN_DATE_DATE_TIME);

For custom text

drb.addAutoText("Autotext at top-center",
AutoText.POSITION_HEADER, AutoText.ALIGNMENT_CENTER);

Parameters

All the parameters are constants of the AutoText class.

By the time this how-to was written, the possible autotexts are:

Autotext type

Position

The 2nd parameter is the position, it determines if the autotext will be shown in the header or the footer of the report.

Alignment

The 3rd parameter is the Alignment, it determines the horizontal alignment (left, right, center).

Pattern

The 4th parameter is optional, is only useful when using AUTOTEXT_CREATED_ON. It determines how to format the creation date/time

Note: The Autotext feature uses i18N, so the text can be internationalized changing the report locale like this: drb.addReportLocale(new Locale("es","AR"));

To localize your messages, you have to create a file named “dj-messages_<locale>.properties” where <locale> must be

the desired language-country pair (ie: en_US, es_ES, fr_FR, etc). This file must be in the classpath.

Another possibility is to tell the DJ wich resource bundle to use like this:

drb.addResourceBundle("other_messages");

The key needed for translation are:

autotext.page Page  
autotext.of of  
autotext.created_on Created on_

For an usage example, see the AutotextReportTest class