iReport Ultimate Guide - Nimsoft Library

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

13.07.2015 Views

iReport Ultimate GuideThe vertical dimension is not important because, when you print the report, UR will use all the vertical spacenecessary, regardless of the element size (see Figure 10-12).3. Select the subreport element so that the property sheet shows its properties (Figure 10-13).Figure 10-13 Subreport properties4. We want to use the same database connection we used with the master report to populate the subreport, so set theconnection type to Use a connection expression. The expression will be just $P{REPORT_CONNECTION}.As explained, REPORT_CONNECTION is a built-in parameter holding a reference to the connection used in the report.5. Next, define the subreport expression; it is used by UR to locate the report that will be inserted as a subreport.Assuming the subreport Jasper file is in the classpath (from an iReport perspective it’s enough that it is in the samedirectory as the master report), the expression we’ll use is this:“subreport.jasper”6. Finally, since the subreport we are using requires the COUNTRY parameter, add a subreport parameter (by clicking on the ...button of the Parameters property). Click Add and set the subreport parameter name COUNTRY (the name must matchthe parameter name we defined in step step 3 on page 157); as expression for the value, we choose the field containingthe country name, that is, $F{SHIPCOUNTRY} (step step 3 on page 156).7. Preview the report. If everything has been done correctly, you should get a result like the one shown in Figure 10-14.160

SubreportsFigure 10-14 The final resultIn this example we created a basic report and subreport. The number of subreports that can be placed in a report is unlimited,and they can be used recursively, meaning that one subreport can contain other subreports. You can create very smallsubreports (only a textfield) and use them to lookup values, you can use a page layout with two subreports side by sideshowing two different lists of values, and so on.A last note. When you have several subreports one after the other, be sure you set the position type of the report element toFloat. In this way, you avoid the risk of overlapping the subreports when the space they require grows. Another suggestion isthat, when using subreports one after the other, place each subreport in a different band, splitting the Detail band using what’s161

SubreportsFigure 10-14 The final resultIn this example we created a basic report and subreport. The number of subreports that can be placed in a report is unlimited,and they can be used recursively, meaning that one subreport can contain other subreports. You can create very smallsubreports (only a textfield) and use them to lookup values, you can use a page layout with two subreports side by sideshowing two different lists of values, and so on.A last note. When you have several subreports one after the other, be sure you set the position type of the report element toFloat. In this way, you avoid the risk of overlapping the subreports when the space they require grows. Another suggestion isthat, when using subreports one after the other, place each subreport in a different band, splitting the Detail band using what’s161

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

Saved successfully!

Ooh no, something went wrong!