I'm new to this list... and new to BeanUtils as well. Somebody pointed out the BeanUtils.copyProperties method to me the other day... and WOW! It's a great function.... just one issue:

I'm using it in a struts application. On one edit form, I've got a number of Integer fields. Some of these can have an empty (null) value. When I populate the form, a null Business Object value converts to a blank string on the input form (this is what I want). Now, when I save that form back to the database, the empty string gets converted to a 0 and stored in the database as a 0. Obviously, when the user edits the same object again, now the form is populated with a 0.

As a workaround, I am doing a manual check after the copyProperties method runs and storing null when the source string was empty.

Questions:
Why does an empty string automatically convert to 0 when converted to an Integer (instead of null)?
Is there a way to alter the default conversions that occur?
Is there a way to alter the conversions on a per-property basis? (For some fields the blank->0 conversion may be desirable)


Thanks for the help,
Aaron


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to