iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library

13.07.2015 Views

iReport Ultimate Guide1. First, create a new empty report called master.jrxml. Let’s assume that the currently active connection points toJasperReports Sample database.2. Set the query as follow; it is designed to extract the names of countries, ordered by name:select distinct shipcountry from orders order by shipcountryIf iReport does not provide the data automatically, click Read Fields to get the fields from the query (Figure 10-5).Figure 10-5Selecting records for the master report3. The SHIPCOUNTRY field should appear in the outline view. Drag the field into the Detail band, adjusting the textfieldand font size (Figure 10-6).Figure 10-6SHIPCOUNTRY field in Detail band4. Test the report by clicking the Preview button. You should get something similar to Figure 10-7.156

SubreportsFigure 10-7Just a list of countriesNext, let’s start to create the report that will be used as the subreport. The subreport must have the following characteristics:• No margins (this is not mandatory, but of course we don’t need them).• No parameter to host the name of the country.• The width must be congruent with the space we want to reserve for it in the master report; let’s use the entire page widthminus the margins.• A set of textfields in the Detail band to show first and last name of each customer.1. Create a new empty report called subreport.jrxml (if you pick a different name, keep it in mind because we will use itwhen connecting the master to the subreport).2. Remove the page margins and adjust the page width (that is, an A4 page has a width of 595 pixels, subtracting 20 pixelsfor the left margin and 20 for the right one, the new page should be set to a width of 555 pixels with margins of 0).3. Add to this report a parameter that we’ll call COUNTRY.The type must be set to java.lang.String and the default value to a blank string (“”) or, if you prefer, to a countryname like “Argentina”. This default value will be overridden by whatever we specify from the master report. We areassigning it to the parameter now only because a default value in iReport (not in UR) is mandatory when usinga parameter inside a report query.4. Open the query dialog and enter the query to select the customer information based on the order’s country; it can besomething like this:select distinct shipname, shipcity from orders where shipcountry = $P{COUNTRY}157

<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>1. First, create a new empty report called master.jrxml. Let’s assume that the currently active connection points toJasperReports Sample database.2. Set the query as follow; it is designed to extract the names of countries, ordered by name:select distinct shipcountry from orders order by shipcountryIf <strong>iReport</strong> does not provide the data automatically, click Read Fields to get the fields from the query (Figure 10-5).Figure 10-5Selecting records for the master report3. The SHIPCOUNTRY field should appear in the outline view. Drag the field into the Detail band, adjusting the textfieldand font size (Figure 10-6).Figure 10-6SHIPCOUNTRY field in Detail band4. Test the report by clicking the Preview button. You should get something similar to Figure 10-7.156

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!