iReport Ultimate Guide - Nimsoft Library

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

13.07.2015 Views

iReport Ultimate Guidecalled a “fake group.” This is a group having as expression, for instance, the REPORT_COUNT parameter, which ensures thatyou will get the fake group header and footer bands for each detail. In this way, you will optimize the report generation.10.3 Returning Values from a SubreportIn a report, it is often useful to get the result of some kind of calculation that has been performed in a subreport (for instance,the number of records).UR provides a feature that allows users to retrieve values from within a subreport. This mechanism works much thesame as passing input parameters to subreports. The idea is to save values calculated during the filling of the subreport intovariables in the master report.Bindings between calculated values and local variables can be set in the Subreport Return Values property in the propertysheet.Let’s see how to use it with the sample we created in the previous section. Suppose we want to print in the master report thenumber of cities we have found for each country. From the subreport perspective, this value is represented by theREPORT_COUNT variable, which is not accessible directly from the master report. So the first step is to create a variable to hostthis value at the end of the subreport elaboration. The variable must be consistent with the value it will host. In this case, it isan integer.1. In the master report, create a new variable (let’s call it SUBREPORT_COUNT) that is type java.lang.Integer andcalculation type System.2. Select the subreport element and open the Return Values property dialog by clicking the appropriate ... button(Figure 10-15).Figure 10-15 Subreport Return Values162

Subreports3. Click the Add button to create the new return value; the Add/Modify variable dialog will appear (Figure 10-16):Figure 10-16 The Subreport Return Value Definition dialog4. Select a calculated value from the subreport’s built-in variables (REPORT_COUNT), as well as the local variable that willcontain the values returned by the variable (SUBREPORT_COUNT).5. Next, select a calculation type.If you want a subreport value to be returned as-is, select the type Nothing. Otherwise, several calculation types can beselected. For example, if the desired value is the average of the number of records within a subreport that is invokedrepeatedly, set the calculation type to Average.In your master report, when you created a new variable to be used like a container for a returned value, you set thevariable calculation type to System. The effective calculation type performed on the variable values is the onedefined in the dialog box shown in Figure 10-16.The value coming from the subreport is available only when the whole band containing the subreport is printed. If you need toprint this value using a textfield placed in the same band as your subreport, set the evaluation time of the textfield to Band(Figure 10-17).Figure 10-17 A textfield showing the return value (with evaluation time set to Band)The report preview should look like the one in Figure 10-18.163

Subreports3. Click the Add button to create the new return value; the Add/Modify variable dialog will appear (Figure 10-16):Figure 10-16 The Subreport Return Value Definition dialog4. Select a calculated value from the subreport’s built-in variables (REPORT_COUNT), as well as the local variable that willcontain the values returned by the variable (SUBREPORT_COUNT).5. Next, select a calculation type.If you want a subreport value to be returned as-is, select the type Nothing. Otherwise, several calculation types can beselected. For example, if the desired value is the average of the number of records within a subreport that is invokedrepeatedly, set the calculation type to Average.In your master report, when you created a new variable to be used like a container for a returned value, you set thevariable calculation type to System. The effective calculation type performed on the variable values is the onedefined in the dialog box shown in Figure 10-16.The value coming from the subreport is available only when the whole band containing the subreport is printed. If you need toprint this value using a textfield placed in the same band as your subreport, set the evaluation time of the textfield to Band(Figure 10-17).Figure 10-17 A textfield showing the return value (with evaluation time set to Band)The report preview should look like the one in Figure 10-18.163

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

Saved successfully!

Ooh no, something went wrong!