iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate GuideFigure 10-1The Subreport elementAt design time the element will be rendered as a rectangle (Figure 10-2).Figure 10-2Subreport element placed in the Title bandIt is not necessary that the Subreport element be exactly as large as the report we will use as subreport; the element dimensionsare not really meaningful because the subreport will occupy all the space that it needs. You can think of the Subreport elementas a place holder defining the position of the top-left corner to which the subreport will be aligned. However, to avoidunexpected results, it is always better to be precise.10.1.1 Linking a Subreport to the Parent ReportTo link the subreport to the parent report you have to define three things:• How to recover the Jasper object that implements the subreport.• How to feed the object with data.• How to set the values of the subreport parameters.All this information can be defined through the Subreport element property sheet (Figure 10-3).152
SubreportsFigure 10-3Subreport element propertiesFirst, let’s take a look at how subreport parameters are set.10.1.2 Specifying the SubreportWhen we add a subreport to a report, we have to know the location of the Jasper file we’ll use to generate the subreport. Weinstruct UR to locate this file or object setting the subreport expression. As in many other contexts whereexpressions are involved, we need to set its type, that is, the kind of object returned from the expression. It’s easy to imaginethat UR will act differently according to the expression type. The type is set specifying a value for the ExpressionClass property. It must be selected from the combo box (Figure 10-3). Table 10-1 lists the possible object types.Table 10-1Possible values for Subreport ExpressionValuenet.sf.jasperreports.engine.JasperReportjava.io.InputStreamjava.net.URLjava.io.Filejava.lang.StringExplanationThe Jasper file pre-loaded in a UR object.An open stream of the Jasper file.A URL file that identifies the location of the Jasper file.A file object that identifies the Jasper file.The name of the Jasper file.If the expression is a string (java.lang.String), UR will assume that the subreport must be loaded from a Jasperfile and will try to locate the file in the same way that resources are located. Specifically, the string is at first interpreted as aURL. In case of failure (a MalformedURLException being returned), the string is interpreted as a physical path to a file; ifthe file does not exist, the string is interpreted as a resource located in the classpath. This means that using an expression oftype String means you are in some way trying to specify a file path; optionally, you can put your Jasper file in the classpathand refer to it as a resource (meaning your expression will be something like “subreport.jasper,” assuming that thedirectory containing the file subreport.jasper is in the classpath).You might be concerned about why a relative path cannot be used to locate the subreport file; in other words, why, if you havea report in c:\myreport\main_report.jasper, you cannot refer to the subreport just by using an expression like..\\mysubreports\\mysubreport.jasper. Well, you cannot do this because UR does not keep in memory the originallocation of the Jasper file that it’s working with. This makes perfect sense, considering that a Jasper object is not necessarilyloaded from a physical file.The first step in configuring a subreport element should now be clear: create an expression that can be used to load the Jasperobject to use when filling the subreport portion of the document. From experience, 99 percent of the time it will be a Jasper file153
- Page 101 and 102: Fields, Parameters, and Variables6.
- Page 103 and 104: 6.2.3 Built-in ParametersFields, Pa
- Page 105 and 106: Fields, Parameters, and VariablesRe
- Page 107 and 108: Fields, Parameters, and Variables6.
- Page 109 and 110: Fields, Parameters, and VariablesTa
- Page 111 and 112: Bands and GroupsCHAPTER 7BANDS AND
- Page 113 and 114: Bands and Groupsexpression may be r
- Page 115 and 116: Bands and GroupsFigure 7-6Dragging
- Page 117 and 118: Bands and GroupsFigure 7-10The firs
- Page 119 and 120: Bands and GroupsFigure 7-14 shows t
- Page 121 and 122: 7.3 Other Group OptionsBands and Gr
- Page 123 and 124: Fonts and StylesCHAPTER 8FONTS AND
- Page 125 and 126: Fonts and StylesThe list of availab
- Page 127 and 128: Fonts and StylesFigure 8-5Font Exte
- Page 129 and 130: Fonts and StylesFigure 8-7Font Exte
- Page 131 and 132: Fonts and StylesFigure 8-10The new
- Page 133 and 134: Fonts and StylesTo apply a style to
- Page 135 and 136: Fonts and StylesFigure 8-17The outl
- Page 137 and 138: TemplatesCHAPTER 9TEMPLATESOne of t
- Page 139 and 140: TemplatesFigure 9-2Columnar reportA
- Page 141 and 142: TemplatesFigure 9-4Group by step in
- Page 143 and 144: TemplatesIf a static text element i
- Page 145 and 146: TemplatesFigure 9-8Your custom temp
- Page 147 and 148: TemplatesFigure 9-10New template in
- Page 149 and 150: TemplatesFigure 9-12Preview of repo
- Page 151: SubreportsCHAPTER 10 SUBREPORTSSubr
- Page 155 and 156: SubreportsFigure 10-4Subreport Para
- Page 157 and 158: SubreportsFigure 10-7Just a list of
- Page 159 and 160: SubreportsFigure 10-11 Subreport Wi
- Page 161 and 162: SubreportsFigure 10-14 The final re
- Page 163 and 164: Subreports3. Click the Add button t
- Page 165 and 166: Subreports10.4 Using the Subreport
- Page 167 and 168: SubreportsFigure 10-21 Subreport co
- Page 169 and 170: SubreportsFigure 10-23 Setting Subr
- Page 171 and 172: Data Sources and Query ExecutersCHA
- Page 173 and 174: Data Sources and Query Executers•
- Page 175 and 176: Data Sources and Query ExecutersFig
- Page 177 and 178: Data Sources and Query ExecutersFig
- Page 179 and 180: Data Sources and Query ExecutersFig
- Page 181 and 182: Data Sources and Query ExecutersFig
- Page 183 and 184: Data Sources and Query ExecutersFig
- Page 185 and 186: Data Sources and Query ExecutersFig
- Page 187 and 188: Data Sources and Query Executers•
- Page 189 and 190: Data Sources and Query ExecutersAft
- Page 191 and 192: Data Sources and Query ExecutersIns
- Page 193 and 194: Data Sources and Query Executerspub
- Page 195 and 196: Data Sources and Query ExecutersFig
- Page 197 and 198: Data Sources and Query ExecutersFig
- Page 199 and 200: Data Sources and Query Executersbe
- Page 201 and 202: Data Sources and Query ExecutersFig
SubreportsFigure 10-3Subreport element propertiesFirst, let’s take a look at how subreport parameters are set.10.1.2 Specifying the SubreportWhen we add a subreport to a report, we have to know the location of the Jasper file we’ll use to generate the subreport. Weinstruct UR to locate this file or object setting the subreport expression. As in many other contexts whereexpressions are involved, we need to set its type, that is, the kind of object returned from the expression. It’s easy to imaginethat UR will act differently according to the expression type. The type is set specifying a value for the ExpressionClass property. It must be selected from the combo box (Figure 10-3). Table 10-1 lists the possible object types.Table 10-1Possible values for Subreport ExpressionValuenet.sf.jasperreports.engine.JasperReportjava.io.InputStreamjava.net.URLjava.io.Filejava.lang.StringExplanationThe Jasper file pre-loaded in a UR object.An open stream of the Jasper file.A URL file that identifies the location of the Jasper file.A file object that identifies the Jasper file.The name of the Jasper file.If the expression is a string (java.lang.String), UR will assume that the subreport must be loaded from a Jasperfile and will try to locate the file in the same way that resources are located. Specifically, the string is at first interpreted as aURL. In case of failure (a MalformedURLException being returned), the string is interpreted as a physical path to a file; ifthe file does not exist, the string is interpreted as a resource located in the classpath. This means that using an expression oftype String means you are in some way trying to specify a file path; optionally, you can put your Jasper file in the classpathand refer to it as a resource (meaning your expression will be something like “subreport.jasper,” assuming that thedirectory containing the file subreport.jasper is in the classpath).You might be concerned about why a relative path cannot be used to locate the subreport file; in other words, why, if you havea report in c:\myreport\main_report.jasper, you cannot refer to the subreport just by using an expression like..\\mysubreports\\mysubreport.jasper. Well, you cannot do this because UR does not keep in memory the originallocation of the Jasper file that it’s working with. This makes perfect sense, considering that a Jasper object is not necessarilyloaded from a physical file.The first step in configuring a subreport element should now be clear: create an expression that can be used to load the Jasperobject to use when filling the subreport portion of the document. From experience, 99 percent of the time it will be a Jasper file153