You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Tomáš Procházka <t....@centrum.cz> on 2007/09/02 21:07:15 UTC

[BeanUtils] default value for BigDecimalConverter

Hi.

I have question related ConvertUtilsBeans class.

Why all Converters has defined default value, only BigDecimalConverter and BigIntegerConverter not?  When I need populate any bean with BigDecimal it's fail on this if value is "". For example forms in Strus framework. When I have Integer field and user send empty string BeanBindings convert it to 0, but when I jave BigDecimal field get only:

org.apache.commons.beanutils.ConversionException


-- 
Tomas Prochazka


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [BeanUtils] default value for BigDecimalConverter

Posted by Niall Pemberton <ni...@gmail.com>.
On 9/2/07, Tomáš Procházka <t....@centrum.cz> wrote:
> Hi.
>
> I have question related ConvertUtilsBeans class.
>
> Why all Converters has defined default value, only BigDecimalConverter and BigIntegerConverter not?  When I need populate any bean with BigDecimal it's fail on this if value is "". For example forms in Strus framework. When I have Integer field and user send empty string BeanBindings convert it to 0, but when I jave BigDecimal field get only:
>
> org.apache.commons.beanutils.ConversionException


I believe it was a mistake when BigDecimal / BigInteger converters
were added that they didn't provide a default value and wasn't
subsequently changed for compatibility reasons. You can simply
register instances of those converters with default values yourself to
overcome this:

Converter converter = new BigDecimalConverter(new BigDecimal("0.0"));
ConvertUtils.register(converter, BigDecimal.class);

Niall


> --
> Tomas Prochazka

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org