Jasper iReport Code Snippets

Objective

This page contains snippets and blocks of code that are useful for editing iReport XML templates.

Difficulty: Expert

Page Contents

 

Assumptions

  • You have full admin access to ParadigmEMS

  • You are a competent user of ParadigmEMS

  • You have already downloaded Jasper iReport v3.0

Implications

Warning

Use the following as a checklist before uploading a modified iReport template into Paradigm

1. Never change the report file name
2. Only full admin users can edit reports
3. Compile before uploading a changed document
4. Make sure all elements are NOT bordered in red as that suggests the element is not positioned correctly
5. Do not move elements or fields out of their default bands

Blank Page Unwanted As The Last Page of Your Document

Check whether the Summary Band was being used during testing. The band will likely have a height of zero, and it may have a small height but contain no fields.

Open the Report Properties dialog box and check inside the More tab whether you have a tick in the box for ‘Summary on a new page’. If you have a tick, remove it.

Click on the View option of the main menu and click Bands. The ‘Print When Expression’ may contain the legacy code similar to

new Boolean($P{authUsername}.equals("Silverband.Fulladmin"))

Removing this condition will prevent the Summary Band from appearing only for our Fulladmin user.

Java Conditions

new Boolean($P{letterNumber}.equalsIgnoreCase("1st")||$P{letterNumber}.equalsIgnoreCase("2nd")) new Boolean ( ! $F{provider_code}.equals( "Morling" ) ) new Boolean( $V{amountDueTotal}.compareTo( new Double (0.00) ) > 0 ) new Boolean ( $V{PAGE_NUMBER}.toString().equals("1" ) new Boolean( $V{PAGE_NUMBER}.intValue() == 1) new Boolean ($F{chessn}!=null && !$P{unitEnrolmentEndDate}.equals("")) new Boolean ( $F{course_level}.equals("VET")) new Boolean ( $F{enrolment_status_id}.equals( "ENROLMENT_COMPLETED" ) )

Dates

new SimpleDateFormat("dd MMMM yyyy").format( new Date()) # Passing in a date string to be used in a date function # year = integer for years since 1900 # month between 0 and 11 with 0 = Jan # days between 1 and 31 # 1st Jan 2021 would be coded as follows: new Date(121,0,1) new java.util.Date(2017, 1, 1) "Teaching Period: " + new SimpleDateFormat("dd MMMM yyyy").format( $F{current_semester_name} ) new SimpleDateFormat("EEEEE, dd MMMMM yyyy").parse($P{todaysDate}) new SimpleDateFormat("dd/MM/yyyy").format($P{report_date}) "Admitted to the "+$F{course_name}+" on "+new SimpleDateFormat("MMMMM dd, yyyy").format($F{course_enrolment_start_date}) to include st, nd, rd, th in date, do it in SQL, and pass string field to ireport instead of date field: to_char(epe.grad_date, 'DDth FMMonth YYYY') within ireport: new SimpleDateFormat("ddth MMMM yyyy").format(new Date())

Casting

"You currently owe: $" + new DecimalFormat("###0.00").format($V{amountDueTotal}).toString() $V{PAGE_NUMBER}.toString() "Total credit points required: " + new DecimalFormat("0").format($F{credit_points_required}).toString() ( $V{gpa_total}==null ? new Double (0) : $V{gpa_total} )

Static Field Formatting

Inline Casting of Fields

Uppercase

Text Field Formatting

Be Advised

Select the Text field in target, right click and go Properties. In the Font tab of the field's Properties window, set the "is styled text" to true, and in the Markup drop down, select the "HTML" option. "Is styled text" is now deprecated but still functions.

Bold

Underline

Italic

 

Custom Fonts

We are able to use custom fonts within our letter and report templates but only under certain conditions.

  • Our provider must supply us with the font files in .ttf file format, within a support request ticket related to using the custom fonts in its letter/report templates

  • Our provider must supply us with the license agreement that permits Silverband as a third party, to use the fonts on behalf of our provider, and to embed those fonts within our templates for the sole use of our provider and the documents that it produces from Paradigm

  • Our provider must supply us with the receipt that proves their purchase of the font files.

 

  1. In the directory where the iReport template files reside ie. ~/java/ofbiz/education/webapp/reportscreate a new directory called custom_fonts

  2. Paste the .ttf font files into the custom_fonts folder, along with the receipt and the license agreement. All of the related files should be kept together.

  3. Open the iReport template file that is to use the custom fonts.

  4. Open the Properties window for the text field (or many text fields) that is (are) to use the custom font, and choose the Font tab. The provider font license agreement usually does not permit Silverband to use single or multiple local copies of the font files across its hardware for editing purposes.

  5. The Font Name field relates only to what is visible during editing within iReport. Changing the font name has no consequence on the font that is printed in the PDF document.

  6. In the field PDF Font Name, paste the full pathname of the .ttf font file, eg. /opt/ems/java/ofbiz/education/webapp/reports/custom_fonts/very_special_font_file.ttf on legacy systems, or /srv/opt/ems/report_templates/custom_fonts/very_special_font_file.ttf on our more recently created systems.

  7. You must press enter to make the font file effective. It is not sufficient to tab out or tab to another field or click elsewhere on the properties window.

  8. Place a tick in the box for PDF Embedded.

  9. Change any other properties for the font as necessary. Save the file and test the results, preferably on the provider’s test site server.

 

Colour

Dot-points


Hyperlink

The hyperlinkTarget attribute behaves in the same way as the target attribute in HTML. Note that only textFields, images, and charts can be hyperlinked in this way.

To make a textField a hyperlink to an external URL, you need to add the attribute hyperlinkType="Reference" to the element, and add a <hyperlinkReferenceExpression> tag within it. The reference expression is where you put the URL. For example:

Escaping Double Quote

Escaping Special Characters

Replace "&" with "&"

MSWord Entities

Replacing fancy quotes and long dash


Sample Dynamic Where Clauses

Sample Address Blocks

Selecting postal address

 

 

No Data message

Â