iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide6.2.4 Relative DatesiReport 5.0 introduces relative dates. This feature enables you create reports that to filter information based on a date rangerelative to the current system date. To do this, use the following template: where:• indicates the time span you want to use. Options include: DAY, WEEK, MONTH, QUARTER, SEMI, and YEAR.• indicates whether the time span occurs before or after the chosen time span.• indicates the number of the above-mentioned time spans you want to include in the filter.For example, if you want to look at Sales for the prior month, your expression would be MONTH - 1.Relative dates are sensitive to time zones. The relative date expression is calculated in the time zone of the logged-inuser.Only one property is configurable: the start day of the week does not depend on locale.The class attribute of JR Parameter of type Relative Date should have one of the following values:• net.sf.jasperreports.engine.rd.DateRange – if you want to use java.util.Date (Date only).For example: If you want to set a relative date as a default value expression of a JR parameter, use the following relative date-builderpattern:• new DateRangeBuilder("DAY-1").toDateRange()• new DateRangeBuilder(”WEEK").set(Timestamp.class).toDateRange()• new DateRangeBuilder("2012-08-01").toDateRange()• new DateRangeBuilder("2012-08-01 12:34:56").toDateRange();For queries, Relative dates are not supported by the $P{} function because it can handle only a limited number of classes(standard Java classes Integer, String etc.). Instead, a new implementation of pluggable functions and parameters inUR supports relative dates with $X{} functions.The following is a JRXML example that shows data from the previous day:Older reports which have date parameters will work just as before, and Relative Dates functionality will beunavailable. In order to make older reports support relative dates, you will need to modify the JRXML: change theparameter class, and, if needed, set a default value expression. In addition, remember to use the $X{} functioninstead of $P{}.104
Fields, Parameters, and VariablesRelative dates currently do not support keywords like “Week-To-Date”(from the start of the current week to the end of thecurrent day). However, you can emulate that by using IS_BETWEEN:• In JRXML, the query use is:$X{IS_BETWEEN, column, startParam, endParam}where startParam has value WEEK and endParam has value DAY.• Likewise, you can do the same for other time ranges: Year-To-Week, Year-To-Month, etc.6.2.5 Passing Parameters from a ProgramiReport passes parameters from a program “caller” to the print generator using a class that extends the java.util.Mapinterface. Consider the code in Code Example 3-2 on page 43, in particular the following lines:...HashMap hm = new HashMap();...JasperPrint print = JasperFillManager.fillReport(fileName,hm,new JREmptyDataSource());...fillReport is a key method that allows you to create a report instance by specifying the file name as a parameter, aparameter map, and a data source. (This example uses a dummy data source created with the class JREmptyDataSource andan empty parameter map created using a java.util.HashMap object.)Let’s see how to pass a simple parameter to a reporting order to specify the title of a report.The first step is to create a parameter in the report to host the title (that will be a String). We can name this parameterREPORT_TITLE and the class will be java.lang.String (see Figure 6-9).Figure 6-9Definition of the parameter to host the title105
- Page 53 and 54: Report StructureMultiple columns ar
- Page 55 and 56: Report StructureFigure 4-11Properti
- Page 57 and 58: Report StructureAs you can see in F
- Page 59 and 60: Report Structure4.1.3.12 ImportsThe
- Page 61 and 62: Report Structureexample, in a repor
- Page 63 and 64: Report ElementsCHAPTER 5REPORT ELEM
- Page 65 and 66: Report ElementsFigure 5-3Guidelines
- Page 67 and 68: Report ElementsFigure 5-6Element no
- Page 69 and 70: Report ElementsTable 5-1Formatting
- Page 71 and 72: Report ElementsFigure 5-10Table 5-2
- Page 73 and 74: Report ElementsFigure 5-11Custom el
- Page 75 and 76: Report Elements5.1.5.2 RectangleThe
- Page 77 and 78: Report ElementsTable 5-4TypeImage E
- Page 79 and 80: Report ElementsTable 5-5OptionImage
- Page 81 and 82: Report ElementsCode Example 5-1Dyna
- Page 83 and 84: Report ElementsCode Example 5-2Prin
- Page 85 and 86: Report ElementsPDF font namePDF enc
- Page 87 and 88: Report ElementsFor your convenience
- Page 89 and 90: Report ElementsHere there are some
- Page 91 and 92: Report ElementsThe following briefl
- Page 93 and 94: 5.5 Adding Custom Components and Ge
- Page 95 and 96: Fields, Parameters, and VariablesCH
- Page 97 and 98: Fields, Parameters, and VariablesIn
- Page 99 and 100: 6.1.2 Accessing the SQL Query Desig
- Page 101 and 102: Fields, Parameters, and Variables6.
- Page 103: 6.2.3 Built-in ParametersFields, Pa
- 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 and 152: SubreportsCHAPTER 10 SUBREPORTSSubr
- Page 153 and 154: SubreportsFigure 10-3Subreport elem
<strong>iReport</strong> <strong>Ultimate</strong> <strong>Guide</strong>6.2.4 Relative Dates<strong>iReport</strong> 5.0 introduces relative dates. This feature enables you create reports that to filter information based on a date rangerelative to the current system date. To do this, use the following template: where:• indicates the time span you want to use. Options include: DAY, WEEK, MONTH, QUARTER, SEMI, and YEAR.• indicates whether the time span occurs before or after the chosen time span.• indicates the number of the above-mentioned time spans you want to include in the filter.For example, if you want to look at Sales for the prior month, your expression would be MONTH - 1.Relative dates are sensitive to time zones. The relative date expression is calculated in the time zone of the logged-inuser.Only one property is configurable: the start day of the week does not depend on locale.The class attribute of JR Parameter of type Relative Date should have one of the following values:• net.sf.jasperreports.engine.rd.DateRange – if you want to use java.util.Date (Date only).For example: If you want to set a relative date as a default value expression of a JR parameter, use the following relative date-builderpattern:• new DateRangeBuilder("DAY-1").toDateRange()• new DateRangeBuilder(”WEEK").set(Timestamp.class).toDateRange()• new DateRangeBuilder("2012-08-01").toDateRange()• new DateRangeBuilder("2012-08-01 12:34:56").toDateRange();For queries, Relative dates are not supported by the $P{} function because it can handle only a limited number of classes(standard Java classes Integer, String etc.). Instead, a new implementation of pluggable functions and parameters inUR supports relative dates with $X{} functions.The following is a JRXML example that shows data from the previous day:Older reports which have date parameters will work just as before, and Relative Dates functionality will beunavailable. In order to make older reports support relative dates, you will need to modify the JRXML: change theparameter class, and, if needed, set a default value expression. In addition, remember to use the $X{} functioninstead of $P{}.104