Creating your first "Hello
World" report
This recipe is a quick starter for someone who is using iReport for the first time. It shows you what views of your report the tool offers and what type of report components are available. This recipe also teaches you how to quickly make a simple "Hello World" report.
How to do it...
The following ten steps will show you how to make your first "Hello World" report.
1. Run iReport. Click on File and select New from the File menu. A New file dialog will appear, which contains several icons such as Report, Style, Chart Theme, and so on. Each icon represents a type of file you can create. The Report icon comes pre-selected, which means iReport allows you to create reports by default. as shown below:
2. Click on the Report icon on the top-left corner of the New file dialog. You will see a number of report templates available to start building your report.
3. Select the Blank A4 report template and click the Open this Template button at the bottom. Blank A4 is the simplest of all templates and, therefore, is a good starting point to learn iReport and Following UI is appears:
4. Next, you will be prompted to enter a filename for your report. Specify a name of your choice. I call my first report ASimpleBlankA4Report, as shown next. Click the Next button.
5. The Finish dialog will appear saying that you have successfully created your new report.
Click on Finish to dismiss it.
6. iReport will open your blank report in its default view, which shows three tabs: Designer, XML, and Preview.
The Designer tab shows the various sections of your report such as Title, Page Header, Column Header, and so on, as shown in the above screenshot.
7. You will see a Palette of alphabetically arranged components (for example, a break, a chart, a static text, or a text field component) on the right of the main iReport window, as shown in the following screenshot.
Drag a Static Text component from the Palette and drop it into the Title section of your report. Similarly drag-and-drop another Static Text component into the Page Header section of your report.
8. Click on the XML tab, which shows the JasperReports XML (JRXML) code that iReport authors in response to your designer actions in the Designer tab.
You will see that XML code for JasperReports changes every time you drag-and-drop a component from the palette into the designer view of your report.
9. Double-click on the Static Text component of the Title section and type Hello World in it as shown:
10. Finally, switch to the Preview tab, which shows what your "Hello World" report will actually look like
How it works...
JasperReports has defined its own XML-based markup language called JasperReports XML, or JRXML for short. JRXML code contains all the information that is required to specify everything about your report. Therefore, designing a report using JasperReports means you have to perform the following steps:
1. Write JRXML code manually according to the requirements of your report.
2. Parse and compile the JRXML code to generate a JASPER file for your report.
3. Combine your JASPER files with application data to generate your report view.
This process is called filling.
4. Export your report view to a popular format such as PDF or XLS.
You normally need to write Java code to compile, fill, and export your JasperReport.
iReport is a JRXML authoring, compiling, filling, and exporting tool. This means that if you can author JRXML manually and write Java code to perform these tasks (compiling, filling, and exporting), you don't need iReport.
However, it is really troublesome trying to write JRXML manually. The graphical tools and components in iReport make it very easy and quick to author the JRXML according to the design requirements of your reports. iReport performs the following tasks for you to help you generate your report:
1. As a visual authoring tool, it helps you to generate JRXML by just dragging-and-dropping of components. It actually translates your visual actions to JRXML code.
2. It compiles the JRXML to generate a JASPER report file.
3. It also combines JASPER files with application data to generate a print preview for your screen and printer.
4. Then it may export this report preview to a popular format such as PDF or XLS.
iReport provides three integrated views to make your work easier: the designer view (where you design your report graphically), the preview view (where you can see the effects of your design), and the XML view (where you can view and edit the actual XML of a JRXML file).
In steps 8, 9, and 10 of this recipe, you played a little with the Designer, XML, and Preview tabs, respectively. You will need these tabs in almost every report you prepare using iReport.
The Designer tab is perhaps where you will work most of the time. It shows a window in which you will design your report by using different components such as static text, text field, and so on. These components are available in a palette of components on the right of your main iReport window.
In step 7 of this recipe, you played with the palette of components to quickly have an idea of how components are used in your report. The Palette window is split into two sections named Report Elements and Tools. The former contains several graphical components (for example, Static Text, Text Field, Frame, and so on), whereas the latter contains tools such as Current date and Page number.
Comments
Post a Comment