iReport Ultimate Guide - Nimsoft Library

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

13.07.2015 Views

iReport Ultimate Guide150

SubreportsCHAPTER 10 SUBREPORTSSubreports represent one of the most advanced features of UR. They enable the design of very complex reportscreated by inserting one or more reports into another report. All the reports have to be created with similar modalities.You have seen that to generate a report you need three things: a Jasper file, a parameters map (it can be empty) to set a valuefor the report parameters, and a data source (or a JDBC connection) that can be empty. In this chapter, I will explain how topass these three objects to the subreport through the parent report and how to create dynamic connections that are able to filterthe records of the subreport based on the parent’s data. Then I will explain how to return information regarding the subreportcreation to the parent report.This chapter has the following sections:• Creating a Subreport• A Step-by-Step Example• Returning Values from a Subreport• Using the Subreport Wizard10.1 Creating a SubreportAs noted previously, a subreport is simply a report composed of its own JRXML source and compiled in a Jasper file.Generally speaking, creating a subreport is very similar to creating any other report. You have to pay attention only to the printmargins, which are usually set to zero for subreports because a subreport is meant to be a portion of a page, not an entiredocument. The horizontal dimension of the subreport should be as large as the element into which it is placed in the parentreport. To insert it, we use a Subreport element (Figure 10-1).151

SubreportsCHAPTER 10 SUBREPORTSSubreports represent one of the most advanced features of UR. They enable the design of very complex reportscreated by inserting one or more reports into another report. All the reports have to be created with similar modalities.You have seen that to generate a report you need three things: a Jasper file, a parameters map (it can be empty) to set a valuefor the report parameters, and a data source (or a JDBC connection) that can be empty. In this chapter, I will explain how topass these three objects to the subreport through the parent report and how to create dynamic connections that are able to filterthe records of the subreport based on the parent’s data. Then I will explain how to return information regarding the subreportcreation to the parent report.This chapter has the following sections:• Creating a Subreport• A Step-by-Step Example• Returning Values from a Subreport• Using the Subreport Wizard10.1 Creating a SubreportAs noted previously, a subreport is simply a report composed of its own JRXML source and compiled in a Jasper file.Generally speaking, creating a subreport is very similar to creating any other report. You have to pay attention only to the printmargins, which are usually set to zero for subreports because a subreport is meant to be a portion of a page, not an entiredocument. The horizontal dimension of the subreport should be as large as the element into which it is placed in the parentreport. To insert it, we use a Subreport element (Figure 10-1).151

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

Saved successfully!

Ooh no, something went wrong!