Jasper reports - Changing date and number pattern as per user locale
<p>I have a crosstab where in I need to display dates and numbers as per the country's locale. I understand I need to use the text expression, but I am unable to figure how must I use with parameters. The locale comes in the form of 'en-IN'(for India), 'de-DE'(for Germany) and so on for all the countries. The date and number formats must change as per the locale of the person who as logged in</p>

<p>I have been able to obtain the user locale in the parameter. But, I do not know how to use it in the crosstab. </p>

<p>PFB the jrxml. I keep getting the error expression ID not found</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0  --&gt;
&lt;!-- 2016-11-04T12:23:19 --&gt;
&lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="crosstabmeasure" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e47b3f7d-1e00-4702-a900-be50a229f085"&gt;
    &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="mysql251"/&gt;
    &lt;import value="org.apache.commons.lang3.time.*"/&gt;
    &lt;style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF"&gt;
        &lt;box&gt;
            &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;topPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;leftPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;bottomPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;rightPen lineWidth="0.5" lineColor="#000000"/&gt;
        &lt;/box&gt;
    &lt;/style&gt;
    &lt;style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF"&gt;
        &lt;box&gt;
            &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;topPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;leftPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;bottomPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;rightPen lineWidth="0.5" lineColor="#000000"/&gt;
        &lt;/box&gt;
    &lt;/style&gt;
    &lt;style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3"&gt;
        &lt;box&gt;
            &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;topPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;leftPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;bottomPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;rightPen lineWidth="0.5" lineColor="#000000"/&gt;
        &lt;/box&gt;
    &lt;/style&gt;
    &lt;style name="Crosstab_CD" mode="Opaque" backcolor="#FFFFFF"&gt;
        &lt;box&gt;
            &lt;pen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;topPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;leftPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;bottomPen lineWidth="0.5" lineColor="#000000"/&gt;
            &lt;rightPen lineWidth="0.5" lineColor="#000000"/&gt;
        &lt;/box&gt;
    &lt;/style&gt;
    &lt;subDataset name="set1" uuid="0271cb46-f184-47b2-8ab3-e6ee96ea33ef"&gt;
        &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="mysql251"/&gt;
        &lt;parameter name="Locale" class="java.lang.String"&gt;
            &lt;defaultValueExpression&gt;&lt;![CDATA["en-IN"]]&gt;&lt;/defaultValueExpression&gt;
        &lt;/parameter&gt;
        &lt;parameter name="UtcOffSet" class="java.lang.Integer"&gt;
            &lt;defaultValueExpression&gt;&lt;![CDATA[330]]&gt;&lt;/defaultValueExpression&gt;
        &lt;/parameter&gt;
        &lt;queryString&gt;
            &lt;![CDATA[select * from internatioinlization]]&gt;
        &lt;/queryString&gt;
        &lt;field name="col1" class="java.lang.String"&gt;
            &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
        &lt;/field&gt;
        &lt;field name="col2" class="java.lang.Integer"&gt;
            &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
        &lt;/field&gt;
        &lt;field name="col3" class="java.sql.Timestamp"&gt;
            &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
        &lt;/field&gt;
        &lt;field name="col4" class="java.lang.String"&gt;
            &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
        &lt;/field&gt;
    &lt;/subDataset&gt;
    &lt;parameter name="Locale" class="java.lang.String"&gt;
        &lt;defaultValueExpression&gt;&lt;![CDATA["en-IN"]]&gt;&lt;/defaultValueExpression&gt;
    &lt;/parameter&gt;
    &lt;parameter name="UtcOffSet" class="java.lang.Integer"&gt;
        &lt;defaultValueExpression&gt;&lt;![CDATA["fi-FI"]]&gt;&lt;/defaultValueExpression&gt;
    &lt;/parameter&gt;
    &lt;queryString&gt;
        &lt;![CDATA[select * from internatioinlization]]&gt;
    &lt;/queryString&gt;
    &lt;field name="col1" class="java.lang.String"&gt;
        &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
    &lt;/field&gt;
    &lt;field name="col2" class="java.lang.Integer"&gt;
        &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
    &lt;/field&gt;
    &lt;field name="col3" class="java.sql.Timestamp"&gt;
        &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
    &lt;/field&gt;
    &lt;field name="col4" class="java.lang.String"&gt;
        &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
    &lt;/field&gt;
    &lt;background&gt;
        &lt;band splitType="Stretch"/&gt;
    &lt;/background&gt;
    &lt;summary&gt;
        &lt;band height="211" splitType="Stretch"&gt;
            &lt;crosstab&gt;
                &lt;reportElement x="0" y="0" width="555" height="211" uuid="6c5ccb8a-50fc-4158-b2ba-88d864aa1e43"/&gt;
                &lt;crosstabParameter name="Parameter1"/&gt;
                &lt;crosstabParameter name="Parameter2" class="java.lang.Integer"/&gt;
                &lt;crosstabDataset&gt;
                    &lt;dataset&gt;
                        &lt;datasetRun subDataset="set1" uuid="d255c9b9-fbb2-420a-8ef5-3236098654f1"&gt;
                            &lt;datasetParameter name="Locale"&gt;
                                &lt;datasetParameterExpression&gt;&lt;![CDATA[$P{Locale}]]&gt;&lt;/datasetParameterExpression&gt;
                            &lt;/datasetParameter&gt;
                            &lt;datasetParameter name="UtcOffSet"&gt;
                                &lt;datasetParameterExpression&gt;&lt;![CDATA[$P{UtcOffSet}]]&gt;&lt;/datasetParameterExpression&gt;
                            &lt;/datasetParameter&gt;
                            &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
                        &lt;/datasetRun&gt;
                    &lt;/dataset&gt;
                &lt;/crosstabDataset&gt;
                &lt;rowGroup name="col11" width="60"&gt;
                    &lt;bucket class="java.lang.String"&gt;
                        &lt;bucketExpression&gt;&lt;![CDATA[$F{col1}]]&gt;&lt;/bucketExpression&gt;
                    &lt;/bucket&gt;
                    &lt;crosstabRowHeader&gt;
                        &lt;cellContents mode="Opaque" style="Crosstab_CH"&gt;
                            &lt;textField&gt;
                                &lt;reportElement x="0" y="0" width="60" height="20" uuid="86c09a7f-46b5-4d2f-ba87-715f99d832a8"/&gt;
                                &lt;textFieldExpression&gt;&lt;![CDATA[$V{col11}]]&gt;&lt;/textFieldExpression&gt;
                            &lt;/textField&gt;
                        &lt;/cellContents&gt;
                    &lt;/crosstabRowHeader&gt;
                    &lt;crosstabTotalRowHeader&gt;
                        &lt;cellContents&gt;
                            &lt;staticText&gt;
                                &lt;reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="94fca0ea-1572-4d42-85d9-b06f92c73b6e"/&gt;
                                &lt;text&gt;&lt;![CDATA[Total col11]]&gt;&lt;/text&gt;
                            &lt;/staticText&gt;
                        &lt;/cellContents&gt;
                    &lt;/crosstabTotalRowHeader&gt;
                &lt;/rowGroup&gt;
                &lt;columnGroup name="col41" height="20"&gt;
                    &lt;bucket class="java.lang.String"&gt;
                        &lt;bucketExpression&gt;&lt;![CDATA[$F{col4}]]&gt;&lt;/bucketExpression&gt;
                    &lt;/bucket&gt;
                    &lt;crosstabColumnHeader&gt;
                        &lt;cellContents mode="Opaque" style="Crosstab_CH"&gt;
                            &lt;property name="com.jaspersoft.studio.unit.width" value="pixel"/&gt;
                            &lt;textField&gt;
                                &lt;reportElement x="0" y="0" width="120" height="20" uuid="137ef406-6a2e-4629-9d38-4858c4a5ae2c"&gt;
                                    &lt;property name="com.jaspersoft.studio.unit.width" value="pixel"/&gt;
                                &lt;/reportElement&gt;
                                &lt;textFieldExpression&gt;&lt;![CDATA[$V{col41}]]&gt;&lt;/textFieldExpression&gt;
                            &lt;/textField&gt;
                        &lt;/cellContents&gt;
                    &lt;/crosstabColumnHeader&gt;
                    &lt;crosstabTotalColumnHeader&gt;
                        &lt;cellContents&gt;
                            &lt;staticText&gt;
                                &lt;reportElement x="0" y="0" width="-2147483648" height="-2147483648" uuid="5c71211d-f1db-4911-8923-2bdb208ddb99"/&gt;
                                &lt;text&gt;&lt;![CDATA[Total col41]]&gt;&lt;/text&gt;
                            &lt;/staticText&gt;
                        &lt;/cellContents&gt;
                    &lt;/crosstabTotalColumnHeader&gt;
                &lt;/columnGroup&gt;
                &lt;measure name="col2_MEASURE1" class="java.lang.Integer"&gt;
                    &lt;measureExpression&gt;&lt;![CDATA[$F{col2}]]&gt;&lt;/measureExpression&gt;
                &lt;/measure&gt;
                &lt;measure name="col3_MEASURE1" class="java.util.Date"&gt;
                    &lt;measureExpression&gt;&lt;![CDATA[$F{col3}]]&gt;&lt;/measureExpression&gt;
                &lt;/measure&gt;
                &lt;crosstabCell width="120" height="20"&gt;
                    &lt;cellContents mode="Opaque" style="Crosstab_CD"&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="0" y="0" width="60" height="20" uuid="861d0d3a-d774-4b0c-ae7d-ace315bf305c"/&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col2_MEASURE1}]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="60" y="0" width="60" height="20" uuid="163ed502-e753-444a-942d-832d84da0a5f"&gt;
                                &lt;property name="com.jaspersoft.studio.unit.y" value="pixel"/&gt;
                                &lt;property name="com.jaspersoft.studio.unit.x" value="pixel"/&gt;
                                &lt;property name="com.jaspersoft.studio.unit.height" value="pixel"/&gt;
                            &lt;/reportElement&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col3_MEASURE1} != null ? DateFormat.getDateInstance(DateFormat.SHORT, new Locale($P{Parameter1}.split("-")[0], $P{Parameter1}.split("-")[1])).format(DateUtils.addMinutes($V{col3_MEASURE1},$P{Parameter2})) : null]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                    &lt;/cellContents&gt;
                &lt;/crosstabCell&gt;
                &lt;crosstabCell width="60" height="20" columnTotalGroup="col41"&gt;
                    &lt;cellContents mode="Opaque" style="Crosstab_CT"&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="2576b9e2-3bba-40e3-aa15-5f4f0aada549"/&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col2_MEASURE1}]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="a111181f-b60f-4afd-8292-9e260c1b9ce2"/&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col3_MEASURE1}]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                    &lt;/cellContents&gt;
                &lt;/crosstabCell&gt;
                &lt;crosstabCell width="60" height="20" rowTotalGroup="col11"&gt;
                    &lt;cellContents mode="Opaque" style="Crosstab_CT"&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="9adf6c9c-acee-4673-8b70-a376e7d1cbb4"/&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col2_MEASURE1}]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="9baedeed-4770-4153-b639-afc0965e9467"/&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col3_MEASURE1}]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                    &lt;/cellContents&gt;
                &lt;/crosstabCell&gt;
                &lt;crosstabCell width="60" height="20" rowTotalGroup="col11" columnTotalGroup="col41"&gt;
                    &lt;cellContents mode="Opaque" style="Crosstab_CT"&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="0" y="0" width="60" height="10" forecolor="#FFFFFF" uuid="a2805e0a-080d-42be-ad86-a7e8e666f571"/&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col2_MEASURE1}]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                        &lt;textField&gt;
                            &lt;reportElement x="0" y="10" width="60" height="10" forecolor="#FFFFFF" uuid="c485f69d-91e1-4b19-a8ab-bdbfa3cafcc6"/&gt;
                            &lt;textFieldExpression&gt;&lt;![CDATA[$V{col3_MEASURE1}]]&gt;&lt;/textFieldExpression&gt;
                        &lt;/textField&gt;
                    &lt;/cellContents&gt;
                &lt;/crosstabCell&gt;
            &lt;/crosstab&gt;
        &lt;/band&gt;
    &lt;/summary&gt;
&lt;/jasperReport&gt;
</code></pre>

<p>Thanks in advance
 Rathi</p>