Jan 29th, 2021
There are two ways to associate the java.util.ResourceBundle
object with the report template.
resourceBundle
attribute of the report template object to the base name of the target resource bundle.java.util.ResourceBundle
object as the value for the REPORT_RESOURCE_BUNDLE
parameter at report-filling time.Example (at design time):
Resources.properties
or Resources_en_GB.properties
localization.home=Home
<jasperReport
...
resourceBundle="Resources"
...
<textField>
<reportElement x="300" y="20" width="50" height="15" />
<textElement textAlignment="Center" />
<textFieldExpression class="java.lang.String"><![CDATA[$R{localization.home}]]></textFieldExpression>
</textField>
In order to internationalization of parameter $P
or dataset field $F
, you can use the method str()
.
<textField>
<reportElement x="300" y="20" width="50" height="15" />
<textElement textAlignment="Center" />
<textFieldExpression><![CDATA[str($F{fieldName})]]></textFieldExpression>
</textField>
If the report needs to be generated in a locale that is different from the current one, the built-in REPORT_LOCALE
parameter can be used to specify the runtime locale when filling the report.
Map<String, Object> parameters = new HashMap();
parameters.put(JRParameter.REPORT_LOCALE, new Locale("en", "GB"));
The common approach, as you mentioned, uses two separated text fields:
Current page number: $V{PAGE_NUMBER}
with EvaluationTime: Now
Total page number: $V{PAGE_NUMBER}
with EvaluationTime: Report
<textField>
<reportElement x="130" y="130" width="120" height="20"/>
<textFieldExpression><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="250" y="130" width="115" height="20"/>
<textFieldExpression><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
</textField>
For JasperReports 6+, use MASTER_CURRENT_PAGE
and MASTER_TOTAL_PAGES
system variables and remember to set the text field evaluationTime
to Master
:
<textField evaluationTime="Master">
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[msg("Page {0} of {1}", $V{MASTER_CURRENT_PAGE}, $V{MASTER_TOTAL_PAGES})]]></textFieldExpression>
</textField>
Create a new band
with splitType="Immediate"
property to add a new page.
<band height="600" splitType="Immediate">
If you need to have a staticText to float below another element with variable height, you can use positionType="Float"
.
Floating object will move down if necessary, but if the previous object is smaller than expected, it doesn’t move up.
According to the documentation, the floating element would have its y
attribute ignored.
<staticText>
<reportElement positionType="Float" x="0" y="190" width="495" height="15" />
<textElement verticalAlignment="Middle" />
<text><![CDATA[Text is here]]></text>
</staticText>