Hi,
I can not set a converter for the type java.lang.Double. I would like to
do that once the we use comma to separate decimals (Using a locale based
converter)
I am using myfaces 1.2.1-snapshot from 17 december, but I tried with
others too.
I use something like that:
<converter>
<converter-id>iDoubleConverter</converter-id>
<converter-for-class>java.lang.Double</converter-for-class>
<converter-class>jsf.converter.InternationalDoubleConverter</converter-class>
</converter>
And my converter:
===============================
public Object getAsObject(FacesContext facesContext, UIComponent
uiComponent, String value) {
FacesContext fc = FacesContext.getCurrentInstance();
Locale l = fc.getViewRoot().getLocale();
if (value != null) {
value = value.trim();
if (value.length() > 0) {
try {
return
NumberFormat.getNumberInstance(l).parse(value).doubleValue();
} catch (ParseException ex) {
throw new ConverterException("Bad String " + value +
" " + l);
} catch (NumberFormatException e) {
throw new ConverterException("Format is not a Number
for locale" + l);
}
}
}
return null;
}
public String getAsString(FacesContext facesContext, UIComponent
uiComponent, Object value) {
if (value == null) {
return "";
}
if (value instanceof String) {
return (String) value;
}
try {
FacesContext fc = FacesContext.getCurrentInstance();
Locale l = fc.getViewRoot().getLocale();
log.debug("Converting Object" + value + " to " + l.toString());
return NumberFormat.getNumberInstance(l).format(value);
} catch (Exception e) {
throw new ConverterException("Format is not a Number");
}
}
============
If I use a converter in the component, it will work, showing that the
converter is working, but I woul like to register it to all Double objects.
Is this a bug from myfaces?