Here's a code snippet from a getValueAsString()
method from an ExtendedViewColumnConverter
class that handles number formatting based on the user locale.
The code assumes that the variable currentLocale
contains the user locale. currentLocale is an instance of java.util.Locale.Locale and I assume that you have logik that handles this e.g. as part of a user bean. If not, then one way of getting the current locale is to do this:
Locale currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
You should of course have an already working customizer bean (that extends DominoViewCustomizer
).
public static class ExtendedViewColumnConverter extends ViewColumnConverter {
...
@Override
public String getValueAsString(final FacesContext context, final UIComponent component, final Object value) {
if (value instanceof Number) {
NumberFormat nf = NumberFormat.getInstance(currentLocale);
DecimalFormat df = (DecimalFormat) nf;
df.setRoundingMode(RoundingMode.HALF_UP);
switch (this.colDef.getNumberFmt()) {
case ViewColumn.FMT_GENERAL: {
// no further formatting needed
break;
}
case ViewColumn.FMT_FIXED: {
df.setMinimumFractionDigits(this.colDef.getNumberDigits());
df.setMaximumFractionDigits(this.colDef.getNumberDigits());
break;
}
default: {
// no further formatting needed
break;
}
}
return df.format(value);
}
}
...
}