Post date: May 12, 2016 4:48:39 PM
I found this on https://gist.github.com/ramannanda9/f59c2f51ac7ccf13839e and adapted it for use in a data grid that uses af:dynamicComponent. It will format the numbers in the grid with data type of DECIMAL (custom name from meta-data) into currency.
@Override
public Converter getConverter() {
Application application =
FacesContext.getCurrentInstance().getApplication();
String dataType = _attributeDef.getDataType();
if (dataType.equals("DECIMAL")) {
Converter converter =
application.createConverter(Number.class);
if (converter != null &&
converter instanceof NumberConverter) {
NumberConverter numberConv = (NumberConverter)converter;
numberConv.setGroupingUsed(false);
numberConv.setPattern("$####,##0");
numberConv.setType("currency");
numberConv.setCurrencySymbol("$");
return numberConv;
}
}
return null;
}