11.8 Displaying Parameters and Selected Criteria in the Report

You can display parameters and selected criteria in a report. To do this, you need to make some changes in the JRXML file.

First, locate the textField-2 of the TemplateReport.jrxml file, which has ā€œ$P{REPORT_SCRIPTLET}.DatePrepare...ā€ showing. This text field is where the selected values of report parameters are displayed. The generated TemplateReport.jrxml file automatically displays the Date/Time Range of the report and the MaxRows parameter and selected value.

$P{REPORT_SCRIPTLET}.DatePrepare($P{ReportType},"F",((new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")).format($P{FromDate})),"D") + " " + $R{HEADER6} + " "  + $P{REPORT_SCRIPTLET}.DatePrepare($P{ReportType},"T",((new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")).format($P{ToDate})),"D") + "\n" +
java.text.MessageFormat.format($R{MAXROWS_COLON}, new
Object[]{
$P{MaxRows}.equals("ALL") ? $R{ALL} :
$P{MaxRows}
})

To add more parameters, simply append to this text field by right-clicking the field and selecting Edit Expression. Add a + ā€œ\nā€ + parameter's label and value for each parameter. To add a label, add the localized label to the properties file as a parameterized string, such as USERS_COLON=Users: {0}. Then, use java.text.MessageFormat to fill in the value.

When the parameter is an OptionQuery, you must also pass the cascaded search name parameter to the JRXML. Then, you can use that value to display on the report for readability instead of showing the IDs. For example, this is the value of textField-2 in the Role Assignments by Member report:

$P{REPORT_SCRIPTLET}.DatePrepare($P{ReportType},"F",((new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")).format($P{FromDate})),"D") + " " + $R{HEADER6} + " "  + $P{REPORT_SCRIPTLET}.DatePrepare($P{ReportType},"T",((new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")).format($P{ToDate})),"D") + "\n" +
java.text.MessageFormat.format($R{MAXROWS_COLON}, new
Object[]{
$P{MaxRows}.equals("ALL") ? $R{ALL} :
$P{MaxRows}
}) + "\n" +
java.text.MessageFormat.format($R{NAME_ORDER_COLON}, new
Object[]{
$P{NAME_ORDER}.equals("lfm") ? $R{NAME_ORDER_LFM} :
$P{NAME_ORDER}.equals("fl") ? $R{NAME_ORDER_FL} :
$P{NAME_ORDER}.equals("lf") ? $R{NAME_ORDER_LF} : $R{NAME_ORDER_FML}
}) + "\n" +
java.text.MessageFormat.format($R{USERS_COLON}, new Object[]{
(($P{User} != null && $P{User}.size() > 0) ? $P{search_name} : $R{ALL})
}) +
"" + ($P{Only_Show_SOD}.booleanValue() ? "\n" + $R{SHOW_SOD} : "")

The Role Assignments by Member parameters displayed are: