Tommy Sadiq Hinrichsen
Tommy Sadiq Hinrichsen

Reputation: 804

Building Jasperreport Textfield message with multiple parameters and types

Im trying to create a message in a textfield which uses a localized string in a properties file. The string has 5 parameters, 1 string, 2 numbers and 2 dates.

For some reason i get this message when trying to compile it.

The method msg(String, Object) in the type JREvaluator is not applicable for the arguments (String, String, Integer, Integer, Date, Date)

Here is the textfield

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="5c7c4cab-cbd4-4c0b-8393-c3b5ba3bc856" positionType="Float" x="0" y="0" width="530" height="20"/>
                <textElement>
                    <font size="14" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[msg($R{report.title},$P{QUERY_LEGAL_ENTITY_NAME},
$P{QUERY_START_ACCOUNT_NUMBER},
$P{QUERY_END_ACCOUNT_NUMBER},
$P{QUERY_START_DATE},
$P{QUERY_END_DATE}
)]]></textFieldExpression>
            </textField>

And here is the properties string

report.title=Finanskonti for {0} | Konti: {1, number} - {2,number} | Datoer: {3,date} - {4,date}

Got any ideas what im doing wrong

Upvotes: 3

Views: 1340

Answers (1)

Tommy Sadiq Hinrichsen
Tommy Sadiq Hinrichsen

Reputation: 804

I got it working using this code

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="5c7c4cab-cbd4-4c0b-8393-c3b5ba3bc856" positionType="Float" x="0" y="0" width="530" height="20"/>
                <textElement>
                    <font size="14" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[msg($R{report.title}, new Object[]{$P{QUERY_LEGAL_ENTITY_NAME},
$P{QUERY_START_ACCOUNT_NUMBER},
$P{QUERY_END_ACCOUNT_NUMBER},
(new SimpleDateFormat("dd-MM-yyyy")).format($P{QUERY_START_DATE}),
(new SimpleDateFormat("dd-MM-yyyy")).format($P{QUERY_END_DATE})}
)]]></textFieldExpression>
            </textField>

hope someone else can use it.

Upvotes: 4

Related Questions