iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate GuideFigure 10-20 The Subreport ExpressionIf you choose the second option, the expression will store the entire absolute path to the subreport Jasper file. This insures thateverything will work in iReport, but it is not very convenient in other environments. For this reason, I suggest that you modifythe expression using the method I described in 10.1.2, “Specifying the Subreport,” on page 153.The subreport is not compiled when you create it. To test your report, you must first preview it. This forces it to be compiled.When you create a new subreport, you can’t specify parameters using the wizard. You will be able to add parameters and usethem in the subreport query after the report is created. So at this point, to filter your subreport query follow these steps:1. Add a parameter to the report implementing your subreport.2. Use that parameter in your query with the typical syntax $P{MyParam} (or $!P{MyParam} if the parameter must beconcatenated with the query as-is).3. In the master report, select the subreport element and add an entry in the subreport parameters list. The new subreportparameter must be called, like the counterpart in the subreport, and its value must be defined using an expression (see thesection 10.1.4, “Passing Parameters,” on page 154” for details).4. If your subreport is not based on an SQL or HQL query, you must still set the subreport data source expression tosuccessfully run your report.5. As mentioned earlier, you can use the Subreport Wizard to create a brand new report that will be referenced as subreportor to refer to an existing report. In the latter case, if the chosen report contains one or more parameters, the wizardprovides an easy way to define a value for each one.10.4.2 Specifying an Existing Report in the Subreport WizardYou can point to an existing report as a subreport with the Subreport Wizard. The first step is to select a JRXML or a Jasperfile in the first screen of the wizard.The second step of the wizard manages expressions for the connection or data source used to fill the subreport (Figure 10-21).166
SubreportsFigure 10-21 Subreport connection setupTo select a connection:• You can select Use the same connection used to fill the master report when using a JDBC-based subreport. The JDBCconnection is passed to the subreport to execute it.• To specify a different JDBC connection, select Use another connection.• To use a JRDataSource object to fill the subreport, select Use a JRDataSource expression and write an expressioncapable of returning a JRDataSource object.• Select Use an empty datasource to set the data source expression to new JREmptyDataSource(). That creates aspecial data source that provides (when declared in this way) a single record with all the field values set to null. This isvery useful when the subreport is used to display static content.In some cases you may want to avoid using any connection or data source, such as when you are displaying static content.Usually a data source or a connection is always required to prevent the subreport being blank. When a subreport does notrequire a data source, though, it is implied that the report property When no data type is set to All Data NoDetails or No Data Section to ensure that at least a portion of the document is actually printed.If the selected report contains parameters, they are listed next (Figure 10-22). For each parameter, you can set a value bychoosing an object from the combo boxes. Of course, you can write your own expression, but no expression editor is providedin this context.167
- 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 and 152: SubreportsCHAPTER 10 SUBREPORTSSubr
- Page 153 and 154: SubreportsFigure 10-3Subreport elem
- 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: Subreports10.4 Using the Subreport
- 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
- Page 203 and 204: Data Sources and Query ExecutersWhe
- Page 205 and 206: Data Sources and Query ExecutersCod
- Page 207 and 208: Data Sources and Query ExecutersPre
- Page 209 and 210: Data Sources and Query ExecutersFig
- Page 211 and 212: Data Sources and Query Executersspe
- Page 213 and 214: Data Sources and Query Executers•
- Page 215 and 216: Data Sources and Query Executersof
SubreportsFigure 10-21 Subreport connection setupTo select a connection:• You can select Use the same connection used to fill the master report when using a JDBC-based subreport. The JDBCconnection is passed to the subreport to execute it.• To specify a different JDBC connection, select Use another connection.• To use a JRDataSource object to fill the subreport, select Use a JRDataSource expression and write an expressioncapable of returning a JRDataSource object.• Select Use an empty datasource to set the data source expression to new JREmptyDataSource(). That creates aspecial data source that provides (when declared in this way) a single record with all the field values set to null. This isvery useful when the subreport is used to display static content.In some cases you may want to avoid using any connection or data source, such as when you are displaying static content.Usually a data source or a connection is always required to prevent the subreport being blank. When a subreport does notrequire a data source, though, it is implied that the report property When no data type is set to All Data NoDetails or No Data Section to ensure that at least a portion of the document is actually printed.If the selected report contains parameters, they are listed next (Figure 10-22). For each parameter, you can set a value bychoosing an object from the combo boxes. Of course, you can write your own expression, but no expression editor is providedin this context.167