How to pass number format/pattern from Servoy to Jasper?

Hello,

I’m struggling with how to pass my number formatting from Servoy to Jasper…

Servoy number types can be formatted using a formatting string such as $#,###.00, and jasper number types can also be formatted (by way of “pattern” property) with the same formatting string. The trouble is though, that I can’t seem to pass it from Servoy to Jasper.

In Servoy I use an i18n key which maps to a formatting string as the formatting string, and that works great so for example I have i18n key Format.Currency which has a value of "$#,###.00. Servoy recognizes the i18n string and replaces it with the value when appropriate. In Jasper, I can get at that same i18n key via the resource syntax e.g. $R{Format.Currency}, however, Jasper does not “parse” the resource bundle string for the pattern property. It just treats it as a formatting string, which is obviously not valid.

For me, because our system is used throughout Latin America, and here in the states, I need to be able to support different currency notations such as $#,###.00 (US) vs. $#.###,00 (LATAM). Right now though because I can’t get the formatting to pass to Jasper I am having to hardcode the US format, which means that my servoy solution is formatting currency correctly depending on which number format a user is using, but then that formatting does not come through on the reports. It’s very awkward.

Any ideas?

Hi Jeff,

Can’t you pass the right formatting string as a parameter to Jasper (via plugins.jasperPluginRMI.runReport()) and use that parameter in the format property of the report elements ?

Regards,

Hello,

the issue seems to be that Jasper does not evaluate the string used in the pattern property, so no, I don’t believe that will work either.

Thanks

Hi!

You can make an calculation (text) that returns the number formatted and used this calculation in Jasper.

For example:
szCurrencyFormat = utils.numberFormat (myNumber ,i18n.getI18NMessage(‘keyFormat’));
and use in Jasper "szCurrencyFormat.

Hello,

Do you mean I should pass szCurrency as a parameter to Jasper and then in Jasper use $P{szCurrency}?

I am not seeing Jasper evaluate any parameters into their values at all in the pattern property. Instead Jasper seems to just use the literal as the pattern.

But maybe I don’t understand what you mean?

Have you done this? Does it work for you? I’m using a little different build of the Jasper jar, so if it works for you, then I must have broken something.

Can you confirm?

The calculation is created in the table, so you spend the foundset to Jasper, can access the calculation field that has a string with the formatted number.

// --- Calculation in the table is named "szNumberFormatting" and type is TEXT
return utils.numberFormat (myFieldNumber ,i18n.getI18NMessage('keyFormat'));

The Calculation is an field over the table and therefore can be read from Jasper.

Hello and thanks. I understand what you are saying, but I’m not passing foundsets.

I’ve posted the question on the Jasper forum here: http://jasperforge.org/plugins/espforum … icid=75283

Let’s see what we get.