commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <ahardy.str...@cyberspaceroad.com>
Subject Re: Making BeanUtils.populate() fail on parse error?
Date Wed, 25 Feb 2009 12:09:07 GMT
Jason Cipriani on 23/02/09 17:16, wrote:
> Currently I am using BeanUtils.populate() to fill a bean with values
> from a map (specifically, with values from the parameter map of an
> HttpServletRequest). However, I noticed that when there is a parse
> error for a field, populate() sets some default value rather than
> failing. E.g. if there is a Long property but the corresponding string
> in the map is "abc", the property is silently set to 0.
> 
> What's the most convenient way to use the beanutils package to fill a
> bean from a parameter map but also be notified if a parse error
> occurs? Is there some way to configure populate() to throw an
> exception, or to otherwise check the conversion status afterwards? Is
> there something else in the library that does this?

Hi Jason
I use BeanUtils in this way too but I haven't come across this one.

Sorry for the late reply, maybe you found a solution. I thought I would probably 
find one myself but got wrapped up in something else.

At first glance it seems it could be that this is the default behaviour for the 
Long type converter. The type converters in BeanUtils are pretty simple and 
don't allow much flexibility. If this is the problem (and a quick look in the 
beanutils source code on the website will confirm it) then you'll have to code 
your own converter which doesn't do this.

Converters are easy, the only pain is that you have to register them with 
ConvertUtils in code at some place in your app.

I'd be interested to hear your progress.

Regards
Adam


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


Mime
View raw message