13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>All the other properties can be left as they are; in particular, we don’t want to set a default value expression. By dragging theparameter into the Title band we can create a textfield to display the REPORT_TITLE parameter (shown in Figure 6-10).Figure 6-10Design panel with the REPORT_PARAMETER displayed in the title bandThis example report is very simple. We just want to focus our attention on how to display the parameter.To set the value of the REPORT_TITLE parameter in our application, modify the code of the previous source code example byadding:...HashMap hm = new HashMap();hm.put(“REPORT_TITLE”,”This is the title of the report”);...JasperPrint print = JasperFillManager.fillReport(fileName,hm,new JREmptyDataSource());...We have included a value for the REPORT_TITLE parameter in the parameter map. You do not need to pass a value for all theparameters. If you don’t provide a value for a certain parameter, UR will assign the value of Default ValueExpression to the parameter with the empty expression evaluated as null.Printing the report, <strong>iReport</strong> includes the String This is the title of the report in the Title band. In this case we justused a simple String. However, it is possible to pass much more complex objects as parameters, such as an image(java.awt.Image) or a data source instance configured to provide a specified subreport with data. The most important thingto remember is that the object passed in the map as the value for a certain parameter must have the same type (or at least be asuper class) of the type of the parameter in the report. Otherwise, <strong>iReport</strong> fails to generate the report, returning aClassCastException error. This is actually pretty obvious; you cannot, for example, assign the value of ajava.util.Date to a a parameter declared as an Integer.106

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

Saved successfully!

Ooh no, something went wrong!