Search code examples
jsfcompositionseparatorvalueconverter

f:convertNumber does not format seperator correctly in ui:composition


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?


Solution

  • 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">