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);
All the parameters are constants of the AutoText class.
By the time this how-to was written, the possible autotexts are:
Adds "Page 1 of 4"
Adds "Page 1/4"
Adds "Page 1"
Adds "Created on <date>" The date will be formatted depending on the pattern parameter (see bellow)
Adds the message passed in the first parameter
The 2nd parameter is the position, it determines if the autotext will be shown in the header or the footer of the report.
The 3rd parameter is the Alignment, it determines the horizontal alignment (left, right, center).
The 4th parameter is optional, is only useful when using AUTOTEXT_CREATED_ON. It determines how to format the creation date/time
Depending on the locale the date will be shown like this: 03/24/2007
Depending on the locale the time will be shown like this: 21:43:47
Depending on the locale the date will be shown like this: 03/24/2007 21:43:47
| 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