Marco Tedone ([EMAIL PROTECTED]) wrote:

> Thank you Dan, your suggestions are inviting...In which cases can you use
> BeanUtils.copyProperties? Sorry for that question, I hadn't time to go
> trough the documentation, so If you can give me some insights, otherwise
> I'll wait until I'll have some more time and will investigate on the
> BeanUtils.copyProperties method.

If you have a form that just populates or updates a bean in your
model (such as a change of address form) you can just retrieve the
model bean (the Address) from the data source, and then use
BeanUtils.copyProperties which will map the getter/setter methods
from your model to your form properties and do the necessary
conversions.  You will have to name your form elements the same name
as your model element names to take advantage of this, but it saves
a lot of editing for when you add a new field.  Image the difference
between

address.setStreet1(form.getAsString("street1"));
address.setStreet2(form.getAsString("street2"));
address.setCity(form.getAsString("city"));
address.setState(form.getAsString("state"));
address.setZipCode(form.getAsString("zipCode"));

and

BeanUtils.copyProperties(address, form);

much simpler for the "common" data.  Then for any fancy stuff (such
as MD5-summing passwords) you go ahead and populate the model bean
using any necessary logic.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <[EMAIL PROTECTED]>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
"I'm old enough to know better, but still too young to care."
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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

Reply via email to