University of Colorado Colorado Springs banner
Login to LibApps.

Print Templates Archive: Java Script

Expressions in Templates

There are various reasons to use Java expressions in a template. These expressions can be inserted into template  text fields to customize template output. Remember a field represent the data library available from Millennium.
For the more advanced user that are familiar with Java, note that these  elements from the data library are of field class type 'java.lang.String'.

Documentation on the Java string library can be found here:
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html

Important: Do not remove any Java expressions embedded in barcode-related data elements. The client might become unstable if you preview or print a template that does not contain the required Java expressions.

 

Example Using Expressions
In this example, the template needed to provide a message targeted for certain ptypes. This message is only shown for ptype(s) "Faculty/Staff" or "Lib faculty". The first step was to add a Text Field element to the template.

This shows the added "Text Field" element within the template:

iReport Add Text Field to Title Band

 


To start customizing the Text Field element, select the element and then select Properties to expand out properties window. The text field will be highlighted to indicate it is active/selected.

iReport Add Text Field Properties

Use the following button next to Text Field Expression...

iReport Browse Button

...to open the "Text Field Expression" editor.

iReport Add Text Field Expression Editor

This is where the expression code needs to be inputted. The code for our example looks like:

// Print office delivery message only to ptypes for staff and faculty
($F{Patron_Type_C}.equals( "Faculty/Staff" ))
||
($F{Patron_Type_C}.equals( "Lib faculty and staff" ))
? "For Office Delivery contact the Circulation Desk at 255-3296."
: ""

 

**NOTE: Be careful when copying and pasting. You may want to paste the expression first into a simple text editor. Then do some cleanup  and paste it into iReport ** 

 

This code will check for the 2 different ptypes ("Faculty/Staff" and "Lib faculty and staff").   If the ptype is either of these, it will print out the message ("For Office Delivery contact the Circulation Desk at 255-3296.").  If the ptype is not one of these it will print nothing.

     

This is the Text Field Expression after being inputted into the editor:

      

Syntax for Java expressions is very important. You must be familiar with how Java expressions are formed.
If the Text Field Expression has a syntax error, it will be displayed within the editor.

       

This is the Text Field Expression editor with an error being displayed:

       

This is the  "Text Field Expression" editor with no errors being detected:

It is a good idea to compile the report to verify there are no errors.

The following icon...

iReport Compile Button

...represents the action to Compile Report. You may want to Compile Report after modifying any templates. This is not required. The more advanced the template becomes compiling it can help troubleshoot any errors with the template. These error will show in the "Report Problems Window and iReport output panels after running Compile Report action.

This shows that the report had no errors:

iReport Add Text Field Compile Report

       

Back to Top