How to Convert a Jasper Report to the New Standards

How to Convert a Jasper Report to the New Standards

Objectives

To teach developers how to change our older style Jasper Reports to match our new design standards.

Prerequisites

JasperSoft Studio 6.14, small amount of Java experience, and very little Jasper Report experience.

Instructions

Parameters, Variables, and Document Editing

Parameters

Adding Parameters

  • First, we need to add a bunch of parameters to our document. I recommend copying these from a report that has already been converted to the new version (like Daily Summary). You can do this two different ways, through the “Outline” tab in the bottom left corner of the IDE, or through the source code:
    • You can right click on the “Parameters” section in the Outline tab to add a parameter. This will automatically add a new parameter, and you can edit this parameter in the “Properties” tab in the bottom right of the IDE. Adjust the name to something meaningful, set the correct class, and set the Default Value Expression to the default value you want to assign this parameter. This value will be used if we don’t pass a value for the parameter to the jasper file when we are generating the report.
    • You can also copy values from the “Parameters” section to another file’s Parameters section. Just Shift-Select which parameters you want (for our new reports, we need HeaderColor, HeaderTextColor, ReportFormat, ShowLogo, Logo, Today, ParameterList, ShortenedParameterList, and ShowCellBackgroundColor), right click, and copy them. Then right-click on the your report’s “Parameters” section and paste.
    • Copying these through the source code is just as easy. The source code can be found by clicking the “Source” button in the bottom left corner of the main editing window. Parameters are marked by the <parameter> tag. You’re looking for the following (I’d recommend not copying directly from the Knowledgebase, as that can cause issues):

 

<parameter class="java.lang.String" name="HeaderColor">
               <defaultvalueexpression><!--[CDATA["#AAAAAA"]]--></defaultvalueexpression>
</parameter>
<parameter class="java.lang.String" name="HeaderTextColor">
               <defaultvalueexpression><!--[CDATA["#000000"]]--></defaultvalueexpression>
</parameter>
<parameter class="java.lang.String" name="ReportFormat">
               <defaultvalueexpression><!--[CDATA["PDF"]]--></defaultvalueexpression>
</parameter>
<parameter class="java.lang.String" isforprompting="false" name="ShowLogo">
               <defaultvalueexpression><!--[CDATA["A"]]--></defaultvalueexpression>
</parameter>
<parameter class="java.awt.Image" isforprompting="false" name="Logo">
               <defaultvalueexpression><!--[CDATA[null]]--></defaultvalueexpression>
</parameter>
<parameter class="java.lang.String" isforprompting="false" name="Today">
<parameter class="java.lang.String" name="ParameterList">
               <defaultvalueexpression><!--[CDATA[null]]--></defaultvalueexpression>
</parameter>
<parameter class="java.lang.String" name="ShortenedParameterList">
               <defaultvalueexpression><!--[CDATA[null]]--></defaultvalueexpression>
</parameter>
<parameter class="java.lang.Boolean" name="ShowCellBackgroundColor">
               <defaultvalueexpression><!--[CDATA[new Boolean(true)]]--></defaultvalueexpression>
</parameter></parameter>

 

  • Only add "ShowChart" if the report has/will have a chart:

<parameter class="java.lang.Boolean" name="ShowChart">
               <defaultvalueexpression><!--[CDATA[new Boolean(true)]]--></defaultvalueexpression>
</parameter>

Showing All Filtering Parameters on the Report

Now, we need to add our filtering parameters to the top of this report. First, ensure that you have added the “ParameterList” and “ShortenedParameterList” to this report. Delete any parameter text elements/subreports in the header section of the report and resize the header accordingly. This includes the text elements that show community name and the “Report for: “ dates.
Next, we must add a text element to our report. We can do that one of two ways: add an element from scratch, or copy and paste from another report, like Daily Summary.

  • To add it from scratch:
    • Drag a new text element from the Basic Elements tab in the top right and drop it into the header section of the report. Size it to be as wide as the report itself, about 15px height, and set it just below the report title.
    • Go to Properties -> Appearance -> Style and Print Details. Make sure you check “Remove Line When Blank
    • Now, go to Properties -> Text Field -> Expression. Set the expression to the following: $V{PAGE_NUMBER} == 1 ? $P{ParameterList} : $P{ShortenedParameterList}
    • Additionally, make sure “Blank When NULL” and “Stretch With Overflow” are both checked. These are just below the Expression property.
  • To add via copy + paste:
    • Copy and paste the text element from a simple report, like Daily Summary. Position it just below the report title.

We can now delete any parameters that were being used to store the path of the subreports we deleted in this process.
Now, make sure you see the Java Code Changes section, and a add .showOnReports() method call to the correct parameters.

Show Parameters in a Separate Sheet on Excel Export

Now that all the work of showing all parameters is done, this step is relatively easy (You can copy+paste the summary section elements from Daily Summary, just ensure that they work properly with your report):

  • Select the summary section in the outline. If it is grayed out, right click it and select “Add Band.” Adjust the height of the band so you can copy and paste the text element we were just working with in the last section.
  • Set Properties -> Text Field -> Expression to: “$P{ParameterList}”
  • If the Summary band is empty (besides the text element you just copied in) set Properties -> Appearance -> Print When -> Print When Expression to “$P{ReportFormat}.equals("XLSX")”
  • If your Summary band has other elements in it, set the Print When Expression of the text element to that value instead. Also, ensure that the summary section will print if exported to Excel.
  • Add a “Break” element from the Basic Elements tab and place it above the subreport element (It MUST be placed above the text element, by at least a pixel)
  • If the Summary band has other elements in it, set the print when expression of the Break element to be the same as the text element’s print when expression (If you added the print when expression to the summary band, disregard this step)
  • Click on the Text element, go to Properties -> Advanced -> Misc -> Edit Properties, and click the button with the ellipses. Search for “net.sf.jasperreports.export.xls.auto.fit.row” and set that property to true.
  • Find the “net.sf.jasperreports.export.xls.sheet.name” property to “Selected Parameters”
  • Go into the source code of the report. Add the following properties to the report:

<property name="net.sf.jasperreports.page.break.no.pagination" value="apply">
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="true">
<property name="net.sf.jasperreports.export.xls.sheet.names.all" value="[REPORT_NAME]">
</property></property></property>

  • Make sure you replace [REPORT_NAME] with the name of your report.

Variables

  • We will be able to delete the TODAY variable. You can do this two ways, through the “Outline” tab in the bottom left corner of the IDE, or through the source code:
    • In the Outline tab, find the “Variables” section. Expand it and find the TODAY variable. Right click on it and select delete.
    • In the source code, scroll down until you see the SQL query (this should be easy to identify). Scroll past this and the <field> tags below that. After these <field> tags you will find all of the variables for this report. Find the one with name=TODAY and delete it.

Correcting Margins

  • Click on the blank, gray area around the report. In the bottom right corner of your IDE, under the “Properties” tab, you should see the title “Report: *report_name*”
  • In the properties tab, under the report section, change "When No Data Type" to be "No Pages".
  • Click on the Advanced subtab and scroll to the bottom to find the “Report Page” category.
  • Here, we can edit the page margins, which are wonky for most of our old reports. Change the Top Margin and Bottom Margin to 30. Usually, Left Margin and Right Margin are already 30, but if they aren’t you should change them to 30.

Bands

Bands are essential to JasperReports and will be printed at different times in the generation of the report. Here is some helpful info on them:

Title Band – Prints at the very top of the page. By default, this only prints on the first page. Most of our reports don’t use this band.

Page Header – Prints just below the Title Band and prints on every page by default.

Column Header – Prints below the Page Header and is usually used to hold our column headings. Many of our reports use this band, but some opt to put the column headings into a Group Header Band. This band will be reprinted on each page by default.

Group Header Bands – On most reports, we have different groups, which can be used to nicely separate data into related sections (like separating accounts on Charge Account Detail). These group headers always print below the Column Header band.
These groups are always associated with a certain field. When the value of that field changes, the Group Footer Band will print, and another Group Header Band will follow that. You can also force the Group Header to start a new page, which is exactly what we do in Charge Account Detail.
Many times, we will want our column headings to be below these Group Header bands. So if a report uses these we will either create a new “ColumnGroup Group Header” (this band will have a null expression, so the group never ends and the group footer will never print) band to hold our column headings, or we will just use one of the Group Heading bands.

Detail – This band prints for every row we get back from the SQL query. For most reports, we will use this band to print out the query data. This band always prints between the Group Header Bands and Group Footer Bands.

Group Footer Bands – Prints when the expression value for the group changes. If this is printed, it is used to show totals for its group and/or subreports.

Column Footer – Prints after all the other data has printed. Generally used to show totals for the whole report.

Page Footer – Prints at the end of each page. Used to show page numbers.

Last Page Footer – Same as Page Footer, but only for the last page. If this is specified, it will replace the Page Footer Band on the last page. If it is not specified, the Page Footer will print on the last page. We don’t need this band, so it can be deleted from old reports.

Summary – Not normally used but has been used for subreports. Prints after the Column Footer.

Page Header Section

  • Delete date printed and the page number elements. Then, copy the logo element and new “Printed: “ element from Daily Summary. If you insist on not copying (and it might be a good idea to go through the following steps on your first couple reports), do the following:
    • Find the image element from the “Basic Elements” tab and drag it into the header section. A popup will appear. Select “No Image”
    • Drag the element into the top left corner. In the “Appearance” tab under the Properties tab in the bottom right corner of the IDE, x and y should be zero.
    • In the Appearance tab and under the “Size” section, set w (Width) to 110 px, and set h (height) to 50 px.
    • Scroll to the bottom of the Appearance tab to the “Print When” section. Click on the button to the right of the “Print When Expression” text element. This will pop up a new dialog, and you can type the following:
      • new Boolean(($P{ShowLogo}.equals( "A" ) || ($P{ShowLogo}.equals( "F" ) && $V{PAGE_NUMBER} == 1)))
    • Go to the “Image” tab under the Properties tab (still in the bottom right corner).
    • Change the Expression value to be “$P{Logo}”
      • Additionally, you can click on the edit expression button (The very right button from the “Expression” label). The expression editor will pop up. Then, click on properties to the left, scroll down to find the “Logo” parameter, and double click it. This will automatically add the logo parameter to the expression.
    • Change the “Error Type” property to “Blank” and the “Using Cache” property to true.
    • Now, for the date printed element: first, drag a “Text Field” object from the Basic elements tab.
    • Move it to the top right corner and edit the width to be 192px and the height to be 14px.
    • Double click the Text Field, which should bring up the Expression Editor (if it doesn’t, ensure that you have a Text Field, not Static Text).
    • Enter the following (including the quotes):
      • “Printed: “ + $P{Today}
    • The Expressions for Text Fields need to return a String, so keep this in mind for the future
    • Editing the font can be found in two locations: one is in the top tool bar (this should pop up if you only have text elements selected, i.e. Text Fields and Static Text) and the other is under the Properties tab and then the Text Field/Static Text tab.
      • Now, edit the font to be Arial, size 8, and align text to the right.
  • Follow the steps in the Showing All Filtering Parameters on the Report Section, if you haven’t already.
  • Shift-Select or Ctrl-Select all text elements in the header section, and change their font to Arial
  • Deselect the title and printed date, then change the font size for everything else to be size 10
  • Size the title to 18, and make sure its bolded.
  • Edit all text elements so they are no longer all-caps and follow a title-case style. Ensure nothing uses toUpperCase().
    • This includes variables and subreports. You can edit variables in two ways:
      • First, you can find the “Variables” section of the Outline in the bottom left of the IDE. Expand this, and you can find the variables you need to edit. Double click them to open up the Expression Editor to edit their values.
      • The second way (and the way I prefer) is by editing the variables in the source code. Go to the “Source” tab. Variables are found below the queryString and fields of the report. Edit these variables so they don’t use toUpperCase(), and ensure the “All” values they return are also in title-case (something like “ALL DEPARTMENTS” or “ALL CUSTOMERS” would be an example).
  • To edit subreports, you need to double click on the subreport element. This will open a new report, most likely consisting of one or two elements. Edit this subreport so the text elements are Arial and size 10 font. Additionally, replace any all caps with title case, and delete any toUpperCase() calls.
  • Ensure title and subtitles are all centered on the report and move the title to y = 40px. If your report doesn’t allow for this for some reason, move the title where appropriate.
  • Click on the Heading section, and go to Properties -> Appearance, scroll to the bottom to the Print When Expression. Click on the button to the right of the text field to open up the Expression Editor. Enter the following:
  • !$P{ReportFormat}.equals("XLSX")
  • We don’t want to print this header when we are exporting to Excel, as this causes issues with Excel’s formatting.

Column Header Section

  • Shift-Select all text elements in this band. Change font to Arial, size 10.
  • Go to Properties -> Appearance and unselect the transparent property under the Color heading
  • With all elements still selected, go to Properties -> Borders
    • Under the “Paddings” section, give Left and Right a padding of 2, Top and Bottom a padding of 1 (this could cause the text to be too large to fit in the text element, so resize the elements as needed)
    • Under the “Borders” Section, click on each line in the border selection box. Change the width to 0.50 and ensure that jasper sets the color by setting the color of the border to #000000 and hitting enter (I know this is the default, but jasper can be a bit finicky on whether it actually sets the color in the source code. This step ensures that it does)
  • If this column represents non-numeric data, dates, apartment numbers, or IDs, the header text should be aligned to the left
  • If this column represents numeric data, the text should be aligned to the right
  • All text elements should be right next to one another, which will make a nice grid pattern. Expand and move columns as needed to achieve this goal. When done, make sure that you table is approximately centered on the report (just eyeball it)
  • Now we need to add the background color and text color. Go to the source code.
    • Find the elements that are in heading. Where they are located can vary from report to report, so I’d recommend searching for the text that one of them contains or the key of the element (found in Properties -> Appearance -> Style and Print Details) until you find the correct elements.
    • The elements your looking for will probably look similar to the following:

<staticText>
<reportElement key="BillCodeLabel-1" mode="Opaque" x="168" y="14" width="103" height="16" forecolor="#000000" backcolor="#EDEDED" uuid="af429997-e95a-48f7-8dea-a475e940fb86">
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
    </reportElement>
    <box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
    </box>
    <textElement textAlignment="Left" verticalAlignment="Middle" rotation="None">
<font fontName="Arial" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
        <paragraph lineSpacing="Single"/>
    </textElement>
        <text><![CDATA[Date]]></text>
</staticText>

  •  
    • The main thing we are interested in is the <reportElement> tag. This example has an opening and separate closing tag, but you could also see them like this:

<reportelement backcolor="#EDEDED" forecolor="#000000" height="16" key="BillCodeLabel-1" mode="Opaque" uuid="af429997-e95a-48f7-8dea-a475e940fb86" width="103" x="168" y="14"></reportelement>

  •  
    • We will add the following propertyExpressions between the reportElement’s opening and closing tags:

<propertyexpression name="net.sf.jasperreports.style.backcolor"><!--[CDATA[$P{HeaderColor}]]--></propertyexpression>
<propertyexpression name="net.sf.jasperreports.style.forecolor"><!--[CDATA[!$P{ReportFormat}.equals("XLSX") ? $P{HeaderTextColor} : "#000000"]]--></propertyexpression>

  •  
    • This will set the background color of the header elements to be the HeaderColor we pass through as a parameter, and set the text color to be HeaderTextColor as long as we aren’t exporting to excel.
    • It is important to note that, if the reportElement has properties and printWhenExpressions, where you place these propertyExpressions matters. For instance, take the following example:

<reportelement backcolor="#FFFFFF" forecolor="#000000" height="16" key="LastNameLabel-1" mode="Opaque" uuid="22e9b2d0-7cab-4622-94fb-08e3bc50067f" width="196" x="101" y="10">
<property name="com.jaspersoft.studio.unit.height" value="px">
               <printwhenexpression><!--[CDATA[!$P{ShowDepartment}]]--></printwhenexpression>
</property></reportelement>

  •  
    • We have a property and a printWhenExpression here. PropertyExpressions must be placed after properties but before printWhenExpressions. So, if we place our expressions, it will look like the following:

<reportelement backcolor="#FFFFFF" forecolor="#000000" height="16" key="LastNameLabel-1" mode="Opaque" uuid="22e9b2d0-7cab-4622-94fb-08e3bc50067f" width="196" x="101" y="10">
<property name="com.jaspersoft.studio.unit.height" value="px">
<propertyexpression name="net.sf.jasperreports.style.backcolor"><!--[CDATA[$P{HeaderColor}]]--></propertyexpression>
<propertyexpression name="net.sf.jasperreports.style.forecolor"><!--[CDATA[!$P{ReportFormat}.equals("XLSX") ? $P{HeaderTextColor} : "#000000"]]--></propertyexpression>
               <printwhenexpression><!--[CDATA[!$P{ShowDepartment}]]--></printwhenexpression>
</property></reportelement>

  •  
    • Now repeat this for all column header elements

Adding (cont.) to Headers

If your report has a heading, like Item Types in Item Type Customer Type Summary, or Departments in the Sales By Dept reports, then those should have the following properties:

  • They should repeat on each page, if their contents spills onto a new page
  • They should have an added “(cont.)” string when they are repeated

There isn’t a simple property value we can change to do this, but it isn’t too difficult to implement:

  • If the header isn’t already repeating on each page, click on the header band, go to Properties -> Appearance -> Group Band Properties and check Reprint Header on Each Page.
  • Add a variable with the following properties:
    • Call it [Heading Name]_START_COUNT
    • Set its initial value expression to be $V{REPORT_COUNT}. The expression field should be empty.
    • Set the reset type to be the group that the header represents (i.e. Item Type, Department, etc.). It that group doesn’t exist, make one.
  • Edit the header text element’s expression to the following:
    • [Header Field Name] + ($V{[Heading Name]_START_COUNT} != $V{REPORT_COUNT} ? " (cont.)" : “”)

This same strategy should work for elements in the data section as well. Although it isn’t a standard to add (cont.) to those elements, it may be helpful to do so depending upon the report.

Data Section

  • Align all elements below their respective column headers. MAKE SURE THESE ELEMENTS ARE THE SAME WIDTH AS THEIR HEADERS. This ensures that we export to excel in the best way possible.
  • We will need to add a style for this section. Again, I’d recommend copying this from another report, but here is what we need (you can copy and paste this either from the Outline tab or in code, like parameters):

<style backcolor="#FFFFFF" mode="Opaque" name="ALTERNATING_BACKCOLOR" type="text/css"><conditionalStyle>
<conditionExpression><![CDATA[new Boolean(($V{REPORT_COUNT} % 2) == 0) && $P{ShowCellBackgroundColor}]]></conditionExpression>
                              <style backcolor="#CBCBCB"/>
               </conditionalStyle></style>

  • Depending on how your report displays its data, this style will vary. If you look through the reports, there are two different ALTERNATING_BACKCOLOR styles: one using $V{REPORT_COUNT} and one using $V{rowCount}
    • REPORT_COUNT is a default variable created by Jasper. It will simply return the current row number of the data directly from our SQL query. Use this variable if your report’s data is printed in the Detail Band and doesn’t separate data with groups
    • rowCount is a custom variable that will vary from report to report. Here are a couple different examples:

<variable calculation="Count" class="java.lang.Integer" name="rowCount" resetgroup="AccountGroup" resettype="Group">
               <variableexpression><!--[CDATA[$V{rowCount} + 1]]--></variableexpression>
               <initialvalueexpression><!--[CDATA[new Integer(1)]]--></initialvalueexpression>
</variable>
<variable calculation="Count" class="java.lang.Integer" incrementgroup="itemCode" incrementtype="Group" name="rowCount">
               <variableexpression><!--[CDATA[$V{rowCount} + 1]]--></variableexpression>
               <initialvalueexpression><!--[CDATA[new Integer(1)]]--></initialvalueexpression>
</variable>

  • The first example has a resetGroup. This means that rowCount will reset back to its initialVariableExpression each time we get a different value for the group (in this case, every time we get a new AccountId, we reset back to 1)
  • The Second example has an incrementType. This means that we will only increment when the group value changes (in this case, for every new item code, rowCount increments). This is extremely useful if your report has its data section in a group footer
  • From my experimentation, it doesn’t really matter what the variableExpression is, as long as it’s something
  • A good rule to go by is: Try REPORT_COUNT first, and if that doesn’t work, use rowCount
  • Just like with the column header section, start by Shift-Selecting all of the elements. Change the font to Arial, size 10
  • Uncheck the “Transparent” property under Properties -> Appearance
  • Change the “Stretch Type” in Properties -> Appearance -> Size to ContainerHeight, and make sure the “Stretch With Overflow” property in Properties -> Text Field is checked
  • Go to Properties -> Appearance -> Style and Print Details and find the “Style” property
    • Select ALTERNATING_BACKCOLOR as the style
  • Again, with all elements selected, go to Properties -> Borders (if one of your elements in your data section is a subreport, deselect it. You’ll have to follow the steps in the “Subreports as Fields” section)
    • Padding: Top and Bottom: 1px, Left and Right: 2px
    • Borders: All sides, 0.5 pen width, and color should be #646464
    • You may have to resize everything after this. In general, I have used a height of 15px for the rows, but if it’s a long report, I use 14px to save space. Make sure your band height matches the height of the elements inside it!
  • Align non-numeric data, dates, apartment numbers, and IDs to the left
  • Align numeric data to the right
  • Click on the data band, and find Split Type under Properties -> Appearance -> Band properties. Change the value to “Prevent”. This ensures that when a row stretches near the end of a page, the row is never divided onto two pages.
  • Now, go back to the source code and search for ALTERNATING_BACKCOLOR, and cycle through the results until you reach the elements in your detail section. It should look similar to the following:

<textField isStretchWithOverflow="true" pattern="MM/dd/yyyy" isBlankWhenNull="false">
<reportElement key="textField" style="ALTERNATING_BACKCOLOR" stretchType="ContainerHeight" mode="Opaque" x="168" y="0" width="103" height="16" forecolor="#000000" backcolor=“#FFFFFF” uuid="82f5df63-28a4-480f-b6a9-0cdf0ecf9f68"/>
    <box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
        <pen lineWidth="0.5" lineColor="#646464"/>
        <topPen lineWidth="0.5" lineColor="#646464"/>
        <bottomPen lineWidth="0.5" lineColor="#646464"/>
    </box>
    <textElement textAlignment="Left" verticalAlignment="Top" rotation="None">
<font fontName="Arial" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
        <paragraph lineSpacing="Single"/>
    </textElement>
                <textFieldExpression><![CDATA[$F{TRANS_DATE}]]></textFieldExpression>
</textField>

  • We want to delete that highlighted “backcolor” attribute. This will override the color of our style, which we don’t want.
  • Next, we need to deal with the pattern. Patterns allow us to format numbers before we display them.
    • Go to Properties -> Text Field of one of your numeric columns.
    • Most of these columns will already have something in their “Pattern” field. In general, this value is what we want, but it can be incorrect.
    • Usually, we want your pattern to be one of the following:
      • Dollars: $#,##0.00
      • Quantity/something that is normally whole numbers, but not always: #,##0.##
      • Something that is ALWAYS whole numbers: ###0
      • Percent: #,##0.00 %
    • If your columns is always dollars, be sure to use the dollars pattern (same can be said for quantity, whole numbers, etc.)
    • If your column varies on what it holds (i.e. dollars, meals, points, etc.), it can get more complicated.
    • A good example of this is Plan Utilization Summary. We use a variable to determine if the report is declining dollar, and if it is we apply a dollar pattern.
    • This requires access to the PLAN.CODE column. If your report doesn’t have this field available, you may just have to go with a more generic pattern:
      •  #,##0.00
    • If your document prints to Excel and you are using the Quantity pattern, you’ll generally get an extra period after whole numbers. We don’t want this, so instead of using a simple pattern, put this into the pattern expression:
      • !$P{ReportFormat}.equals("XLSX") ? "#,##0.##" : ""
      • This will allow us to use the pattern when exporting to everything but Excel. When exporting to Excel, we won’t have a pattern, and won’t get that extra period.

Group Footer Sections/Totals Sections

The total section can be found in either a Group Footer Band or the Column Footer Band. The formatting will be the same as the data sections, with the following exceptions:

  • The top border should be colored #000000, not #646464
  • These fields should not have a style
  • Text should be bolded

Group Footer Sections also may hold subreports. In order to format these, see the Subreport section later in this guide.

No Records Group Footer Section

  • This section only prints if REPORT_COUNT is zero.
  • There is only one text element in this section. Change its font to Arial, size 10, and center the text. Also center the text element on the report.
  • Make the text element as wide as the report, to ensure that the text is centered.
  • Make the element transparent.
  • Make the band the exact same height as the text element, and ensure the text element is positioned at x = 0 and y = 0.


Page Footer Section

  • The Page footer section only has two text elements. Resist all urge to combine these into one text field.
    • The first element says: “Page “ + $V{PAGE_NUMBER} + “ of “
      • The variable PAGE_NUMBER is one that is automatically generated by Jasper.
      • If you check the value of “Evaluation Time” (Properties -> Text Field), you will see that it is set to “Now” (so as soon as Jasper generates this Page Footer, the expression of this element will be evaluated and printed out).
    • The second element says: “ “ + $V{PAGE_NUMBER}
      • How can this work? Well, the evaluation time of this text element is set to “Report”. So after all of the data has been generated and printed onto the report, this element’s expression will be evaluated and printed onto the report. So, whereas the first element gave us the current page number, this will give us the total number of pages
  • Set both elements to have Arial font, size 10, and make sure that the page number is about centered when the report is ran
  • In Properties -> Appearance -> Color, make sure Transparent is checked
  • We don’t want to print this band when exporting to excel, so add the following to the Print When Expression:
  • !$P{ReportFormat}.equals("XLSX")

Last Page Footer Section

This section can be deleted. Just right-click on the section itself (not any elements inside the section) and select delete.

Subreports

Subreports are used in a variety of ways in our reports, but there are three main ways we use them:

  • As subtitles in one of the header sections (These should be deleted)
  • Adding a new, but smaller report to our current report (i.e. they have a table). These summarize data in different ways than the report itself does
  • As fields in our Data Section (this is the least common and can be hard to deal with)

Subreports as Small, Summary Reports

  • These subreports are common in our larger reports, like Items Purchased Summary, Operator Productivity, Charge Account Detail, and Plan Utilization Detail.
  • If these reports only print once (i.e., not printing for each resident, etc.), we want them to print on a separate sheet in Excel. We do this in an extremely similar way to our selected parameters:
    • Add a page break element above the subreport
    • Set its print when expression to be: $P{ReportFormat}.equals(“XLSX”)
    • Set the xls.sheet.name property of the title text element in the subreport file to be the title of the subreport.
    • Ensure you set up everything else correctly for the selected parameters sheet (especially setting those report parameters), and this should work correctly.
  • We will add four parameters to this: ReportFormat, HeaderTextColor, HeaderColor, and ShowCellBackgroundColor. Add these parameters to both the subreport element in this report and to the subreport’s report file.
    • If there are a lot of subreports to add these parameters to, I’d recommend going into the source code to copy the parameters to each element. You’ll need something like the following:

<subreportparameter name="HeaderColor">
               <subreportparameterexpression><!--[CDATA[$P{HeaderColor}]]--></subreportparameterexpression>
</subreportparameter>
<subreportparameter name="HeaderTextColor">
               <subreportparameterexpression><!--[CDATA[$P{HeaderTextColor}]]--></subreportparameterexpression>
</subreportparameter>
<subreportparameter name="ReportFormat">
               <subreportparameterexpression><!--[CDATA[$P{ReportFormat}]]--></subreportparameterexpression>
</subreportparameter>
<subreportparameter name="ShowCellBackgroundColor">
               <subreportparameterexpression><!--[CDATA[$P{ShowCellBackgroundColor}]]--></subreportparameterexpression>
</subreportparameter>

  • In the subreport’s file, format the Column Header and Data sections in the same way that the parent report is formatted.
  • The header section should generally only have the title of the subreport, which should be formatted as Arial, size 12, and bolded.

Subreports as Fields

  • These are the rarest and the most annoying to deal with, so if you can avoid putting a subreport into a data row, please do so. You can find an example of this in Items Purchased Summary. The “% (Qty)” and the “% (Amt)” columns both come from a subreport.
  • The problem with these subreports is that they need to be formatted perfectly in order to be shown on the report correctly, and that they can’t stretch properly with the rest of the row.
  • Double click the subreport to go to the report file. Format it according to the data section’s standards, with the following exception:
    • Don’t put any borders on the text elements and put no shading on them.
  • Since these fields won’t stretch with the rest of the row, having borders on these fields would look off, and result in smaller, empty boxes in our makeshift table.
  • Additionally, ensure that the field/fields in the subreport are the exact same width as the subreport element in the parent report. Since you were formatting and stretching elements, the width of the subreport element most likely changed.
  • Back to the parent report, right click on the subreport element, and select “Enclose in Frame”
  • Looking at the Outline tab, you can see that a new element called “Frame” has been placed in the Data section, and it contains the subreport element.
  • Select the frame in the Outline tab and go to Properties -> Borders. Add the borders in line with the data section’s guidelines, but don’t put any padding on it.
  • Additionally, set Stretch Type in Properties -> Appearance -> Size to “ElementGroupHeight”
  • Set Properties -> Appearance -> Color -> Transparent to be checked.
  • The subreport element will have the ALTERNATING_BACKCOLOR style assigned to it.
    • Why assign it here, and not on the frame? We need the frame to be transparent, as it seems as if it is always loaded on top of the subreport. Since we wouldn’t be able to see the shading (as it is transparent), we put the shading on the subreport element.

Java Code Changes

We also have a few changes to make in our backoffice code.
Under reports/templates, find your report’s template file

  • In the report’s constructor, change the communityId to be the whole community object.
  • Pass the community object into the super constructor instead of the communityId
  • Delete the ReportFormat ReportValue (located inside the reportValueList.addAll() statement.
  • Add the addDefaultFormattingReportValues(reportFormatOptions, defaultReportFormatValue); call after the reportValueList.addAll() statement.
  • If this report has a chart, add ShowChart to the reportValueList:
    • new ReportValue.Builder("ShowChart", "Show Chart", true, true).asBoolean(false).build()
    • Make sure you add this to reportValueList after you call addDefaultFormattingReportValues().
  • If this report overrides updateRenderedView(), make sure you call super.updateRenderedView().
  • If this report uses StandardReport as its constructor, ensure that you use the new constructor that takes the community object, and a new Boolean hasChart.
  • Delete any unused subreport parameters (like any report group subreports we no longer use).

For all of this report’s “filtering parameters” (i.e., parameters that affect the query of the report), we need to add the method call showOnReport() before the build() method call. This ensures that, if the parameter has a value and that value is not its default value, the parameter will show at the top of the report (or in the Selected Parameters sheet, if the report was exported to excel). Note:

  • Common examples of these “filtering parameters” would include report groups, department selections, etc.
  • Parameters like ShowLogo, ShowParameters, ShowCellBackgroundColor, and ReportFormat would not get this showOnReport() call.
  • You don’t need to add this call for BeginDate, EndDate, or PeriodDate.

In ReportService.java:

  • Find the report your working on in the giant switch statement in the buildReport() method.
  • Change the constructor call to use the new constructor
  • If this report uses StandardReport, you will also have to add a Boolean, to determine if you want the showChart variable or not.

 


    • Related Articles

    • Jasper Report Design Standards

      This design standards guide contains all the design decisions we have made to beautify our reports. We expect all these standards to be followed, however we also acknowledge that it may be advantageous to diverge from these standards in order to ...
    • Set up a New Developer Machine

      Set up a New Developer Machine Objectives Set up a Development environment for FullCount Developer from a clean Windows OS installation, after General FullCount tools and software has been added. Outline installation guidelines and additional setup ...
    • Developer Guide

      Installations An installation guide can be found in the Setup a New Developer Machine guide. Version Control Guide We use both Subversion and Git for version control. A crashcourse of our Subversion versioning processes can be found in the Subversion ...
    • Create New Community Record

      Create New Community Record Objectives Setting up a new community record in FullCount and updating applicable documents about the new community Prerequisites Access to production database Access to FullCount google map (requires google account) ...
    • Employee New Hire Checklist

      Employee Name: HR: Yes No Person responsible Comments Is this employee Full Time? Is this employee Part Time? Oasis HR Forms Benefits paperwork Aureon Employee Portal Bank routing info Office: Access (door key) Desk Space (Cube) Additional office ...