1

in my application we're using some input fields directly, and some via a template. The strange thing is that on the inputfield in the template the separator is a dot (.) and those outside the template is a ,

Both inputtexts are completely equal, we even tried to set the same locale for both without success:

in this snippet it's a ,

<p:inputText value="#{manageContracts.dieselFloater}"
                                                                id="dieselFloater" required="true">
                                                                <f:convertNumber maxFractionDigits="2"
                                                                    minFractionDigits="2" locale="de"/>
                                                            </p:inputText>

in this one it's a . (inside an ui:composition):

    <p:inputText value="#{_price}" style="width:140px">
                    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="de" />
                </p:inputText>

does anyone have an idea?

user3172567
  • 461
  • 1
  • 7
  • 19

1 Answers1

0

You can use pattern="" in <f:convertNumber> to specify wether you want a dot (.) or a coma (,).

See documentation : http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_convertNumber.html

See example : http://www.mkyong.com/jsf2/jsf-2-convertnumber-example/

EDIT :

To fix the decimal separator, see this workaround : JSF Locale Change Listener not persistent

It consists to wrap your <ui:composition> in a <f:view locale="de">

Community
  • 1
  • 1
Thrax
  • 1,926
  • 1
  • 17
  • 32
  • Hi, adding pattern="#0,00" didn't work either. – user3172567 Nov 06 '14 at 13:44
  • @user3172567 Try to inspect rendered HTML to verify if it's really not a coma. It could be displayed as a dot if your container is being clipped by another element, or your overflow is being hidden. – Thrax Nov 06 '14 at 14:06
  • inspecting the html code it says value="199.38". I don't know why it ignores the pattern and/or the locale completely. – user3172567 Nov 06 '14 at 14:29
  • @user3172567 The pattern should be `#0.00`. The dot in the pattern is for decimal separator, whereas the coma is for group separator. Since you specified german locale, decimal separator is (.) and group separator is (,). See documentation : http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html – Thrax Nov 06 '14 at 15:20
  • I certainly didn't know that, thanks for telling me. I changed it now to pattern="#0.00' locale = "en" since I want the following format: 123,45. This didn't work either. – user3172567 Nov 07 '14 at 06:32
  • Decimal separator for english locale is a dot so your pattern : `pattern="#0.00' locale = "en"` should render `123.45`. This is normal behaviour. Use `pattern="#0.00' locale = "de"` for your desired output. – Thrax Nov 07 '14 at 09:31
  • I did use for both inputTexts. It works when the inputText is not used in the ui:composition, otherwise it displays a . instead of a , – user3172567 Nov 07 '14 at 09:43
  • Not sure what to do now... Try this workaround : http://stackoverflow.com/questions/6109138/jsf-locale-change-listener-not-persistent (BalusC answer consisting to wrap your `` in a ``) – Thrax Nov 07 '14 at 10:32
  • wrapping the ui:composition in a f:view with locale="de" worked as expected, thank you! – user3172567 Nov 10 '14 at 06:56
  • @user3172567 Glad we managed to make it work. I'm gonna edit my answer for future viewers then. – Thrax Nov 10 '14 at 07:53