Skip to main content

Post 16: iReport: Adding a simple footer to your report

Adding a simple footer to your report
Almost every report has a footer. The simplest footer will provide information about the report such as the name of the report and the date and time when the report was generated among others.

This post teaches you how you will display the name of the report and the date when the report was generated.


How to do it...
The steps to a simple footer design are as follows:
1.  Create the ASimpleFooter.jrxml file such that  the Designer tab of iReport shows that the report contains a main title,  a subtitle and an empty footer, as shown in the following screenshot:



2.  Now you are all set to insert a simple footer into your report. A palette of components is available on the right of the main iReport window. Select the text field component from the palette and drag it into the Page Footer section in the Designer tab.



3.  Right-click on the text field component of step 2 and select the Edit expression option from the pop-up menu. An Expression editor window will open, as shown in the following screenshot:



4.  Delete the default expression ($F{field}) from the Expression editor window.
5.  Click on Parameters in the first column of the lower half of the Expression editor window. This will list all the parameters in the adjacent second column. Scroll down  the list of parameters in the second column to find the JASPER_REPORT parameter
and select it. This will list all methods for this parameter in the adjacent third column. Scroll down the list of methods in the third column to find the getName() method. Double-click on it. This will set $P{JASPER_REPORT}.getName() in the Expression
editor
, as shown in the following screenshot:




6.  Click the Applybutton. This will attach the  ${JASPER_REPORT}.getName() expression to your text field component of step 2.

7.  Switch to the Preview tab and scroll the vertical scroll bar down until you see the footer of your report at the bottom, as shown in the following screenshot:



8.  Switch back to the Designer tab for more editing in the Page Footer section.
9.  Now you are about to insert the current date into your report. Drag a new Current date from the Tools section of the palette and drop it into the Page Footer section of your report, as shown in the following screenshot:





10. A Pattern editor dialog will appear, as shown next. Select Date in the Category column and the appropriate date format from the Type column and click the Apply button.




11. A text field with the new java.util.Date() expression will appear in the Page Footer section of your report. Select this date text field component and  use the arrow keys to roughly align this text field horizontally and vertically to the right-middle position in the Page Footer section of your report, as shown in the following screenshot:


12. Switch to the Preview tab. You will see the current date on the bottom-right corner of your report, as shown in the following screenshot:


13. Switch back to the Designer tab. Select a static text component from the palette and  drag it into the Page Footer section in the Designer tab.



14. Double-click and edit the static text component to add designed by Revan text in it. Then select the static text component and use the arrow keys to select its position, as shown in the following screenshot:


15. Switch to the Preview tab, which shows what your report looks like
 

 16. You have dropped three components (a text field, a date field, and a static text) into  your report. Now you will combine the text field and static text components to improve the look of the Page Footer. Switch back to the Designer tab.

17.  Double-click the static text component and copy the selected text (designed by Revan) by pressing Ctrl+C. Then double-click on the text field component with the expression $P{JASPER_REPORT}.getName(),. The text of expression will be
selected. Deselect the text and move your cursor to the end of the expression. Type +"and then a space, now press Ctrl+V to insert your copied static text (designed by Revan). The expression in the text field component will change to $P{JASPER_REPORT}.getName() +" designed by Revan. Move your cursor  to the end of expression and press the "Enter key of your keyboard. Now your expression in the text field component will look like $P{JASPER_REPORT}.getName() +"
designed by Revan".


18. Delete the static text component by selecting it and pressing the Delete key on your keyboard.

19. Select the text field component with the expression $P{JASPER_REPORT}. getName() +" designed by PACKT"using your mouse and increase its size by dragging its corners to show a full text view.

20. Switch to the Preview tab, which shows what your report looks like.
 
21. You have successfully designed a simple footer for your report. Save it by selecting  Save from the Filemenu.
How it works...
You have learned how to display the name of your report and the date when the report was
generated in the footer. You have also learned the small trick of combining two components
into one in step 17 of the recipe. Switch to the XMLtab to see how all this works:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport>
<!-- other JasperReports XML tags -->
<pageFooter>
<band height="32" splitType="Stretch">
<textField>
<reportElement x="25" y="7"
width="279" height="20"
isPrintInFirstWholeBand="true"/>
<textElement/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{JASPER_REPORT}.getName()
+" designed by PACKT"]]>
</textFieldExpression>
</textField>
<textField pattern="MMMMM dd, yyyy">
<reportElement x="446" y="7" width="100"
height="20"/>
<textElement/>
<textFieldExpression class="java.util.Date">
<![CDATA[new java.util.Date()]]>
</textFieldExpression>
</textField>
</band>
</pageFooter>
<!-- other JasperReports XML tags -->
</jasperReport>
I have shown only a <pageFooter>tag (which corresponds to the Page Footer section of
your report) omitting all the other tags, which are not relevant to this discussion.


The <pageFooter>tag has a <band>child, with two children, both named <textField>.
The first <textField>tag corresponds to the name of the report that you dropped in step 2
of the recipe and later edited in step 17. Notice that the expression and text combination that
you authored in step 17 ($P{JASPER_REPORT}.getName() +" designed by PACKT) is
part of the content inside the first <textField>tag. This means when you followed step 17,
iReport copied the expression and text combination into the first <textField>tag.
The second <textField>tag simply corresponds to the Current date component that you
dropped in step 9 of the recipe.
Also look at the $P{JASPER_REPORT}.getName()expression of step 5. JasperReports
provides many other useful parameters like this JASPER_REPORTparameter, which holds
information about your report (for example, the name of the report, the SQL query used
in your report, and so on). You can follow steps 3, 4, and 5 to play with different available
parameters and their methods to discover the different bits of information you can display
in any text field.







 




Comments

Popular posts from this blog

TIME TABLE: VTU BE/B.Tech June/July 2016 Exam Time table Draft Layout

Semester-wise June-July 2016 Exam time table (Draft Layout) Are You Using updated Kwikstudy App?

Walkins Bangalore: 01st-Oct-2016

1. UTC Aerospace : GET – S&IS-Software Team hiring Electronics & CSE / IT Freshers ! Walkin on 1st OCT | BE/BTECH - 2015 & 2016 both batch can try Selection Process : Written Test Group Discussion Technical & HR Interviews How To Apply : It is a walk-in drive for 2016 batch eligible freshers on 1 Oct 2016 at Bangalore location. Interested and eligible candidates can walk-in to the following venue on 1 Oct 2016 Date of Drive : 01 Oct 2016 Reporting Time : 8:00 AM to 11:30 AM Venue : UTC Aerospace Systems – Site 1, Sy. Nos. 14/1 & 15/1, Maruthi Industrial State, Phase 2, Hoody Village, Whitefield Road, K R Puram Hobli, Bangalore – 560048 ______________________________________ 2. HP : Software Eng/ Software Tester (Call based ,less chance of getting entry , try at your own risk) Event Date : 1-October-2016 Event Time : 8 : 00 am Job Location : Bangalore / Chennai Job Description: Software Engineer /

How to get VTU Provisional Degree Certificate (PDC) ?

Here is the procedure to get the Provisional Degree Certificate from the VTU by passed out candidates. You can get the certificate through post by sending the required documents to VTU. Documents and things required: 1. Provisional Degree Certificate (PDC) application form 2. DD of specified fees amount or print copy of receipt if you paid the fees online 3. A letter to the VTU registrar 4. A4 size envelope Step 1: Fill the PDC application You can download the PDC application form from the VTU website. Click below link for application download. PDC application form download     After downloading the application take a print of it and properly fill the form. Step 2: Make a DD of specified amount as the fees of PDC: Go to the bank and make the DD of prescribed fee amount for the PDC. The fee amount is specified in the above link from where you downloaded the application. Make the DD in favor of " Finance Officer, VTU Belgaum ".   Wr