0

I have an application. There are some setting options for each user. These options are:

thousendSeperator  = You can selected "." or ","
decimalPlaces      = You can selected "." or ","
postionCurrencySymbol = "after" or "previous" => $ 100,00 or 100,00 $

Now I need a pattern for this? The three settings are stored in the database. So I get it from a bean.

I try something like this

    <h:outputText
                        value="#{article.salePrice}">
                        <f:convertNumber
                            pattern="###{loginBean.user.thousendSeperator}###{loginBean.user.decimalPlaces}"
                            currencySymbol="#{article.mandatoryCurrency.currencySymbol}" />
                    </h:outputText>

But it´s not working. Could anybody please help me to fix it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
internet
  • 385
  • 1
  • 8
  • 27

1 Answers1

0

<f:convertNumber> doesn't work like that. For locale-specific currency formats, you need to set type="currency" and locale along with the currency symbol. The actual characters being used for the separators is namely locale dependent. The pattern attribute merely tells the thing how to format the digits and where to position the separators (note: it doesn't tell which characters to use for the separators! this is in turn dependent from the locale).

So, rework your broken model to get hold of the user's locale and the product's currency symbol instead.

<f:convertNumber type="currency" locale="#{user.locale}" currencySymbol="#{product.currency}" />

This way you don't need to remember which separator characters should be used for every single locale known in the world. Java does that all for you.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Is there no option to implement their own pattern? I know it´s comfortable to use e.g. locale="#{user.locale}" but in my application their should it be possible to use their own pattern. Like $ at the suffix oe at prefix. All this columns are stored in the database. Could you help me for a right pattern? – internet Sep 19 '14 at 20:20