Custom BigDecimalConverter for JSF to prevent java.lang.ClassCastException
Using the
<f:convertNumber/>
together with It seems that the BigDecimal results in a java.lang.IllegalArgumentException: java.lang.ClassCastException. To get around this, either use
<f:converter converterId="javax.faces.BigDecimal"/>
or use your own converter, eg:
import java.math.BigDecimal;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.NumberConverter;
public class BigDecimalConverter extends NumberConverter {
public Object getAsObject(FacesContext context, UIComponent component, String string) {
Object value = super.getAsObject(context, component, string);
if (value instanceof Long) return BigDecimal.valueOf((Long) value);
if (value instanceof Double) return BigDecimal.valueOf((Double) value);
return value;
}
}
Thanks so far to jbforum (http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4079626#4079626). But I still have a problem when I want to use something like maxFractionDigits or minFractionDigits. These attributes are not supported by tag…