-1

Suppose I have code like this:

<h:outputFormat value="The number is {0, number, #.##}">
  <f:param value="#{bean.double}" />
</h:outputFormat>

From my understanding, JSF uses MessageFormat(String pattern, Locale locale) method to convert the value. So if my locale is Spanish, and bean.double is 3.72, then the result will be 3,72 even if my SubformatPattern is #.##.

Is there a way to format the number as 3.72 and keep the locale as Spanish?

FYI, I set the locale by using the f:view element with a locale attribute — for example:

<f:view locale="#{localeBean.locale}"/>

Reference:

Community
  • 1
  • 1

1 Answers1

0

You could by overriding the renderer for the outputFormat tag.

Have a look at the Mojarra source for OutputMessageRenderer. Find this statement:

MessageFormat fmt = new MessageFormat(currentValue,
                                      context.getViewRoot().getLocale());

In this statement hardcode the locale to English and you are done.

The easy way would be to simply format your number in your bean using a hardcoded locale and return it as a string, so you can simply use:

<h:outputFormat value="The number is {0}">
  <f:param value="#{bean.formatDouble(bean.double)}" />
</h:outputFormat>

See also:

Community
  • 1
  • 1
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102