For starters, you should generally be using String properties in your form
bean because this is what the JSP sends to you. If you declare an integer in
your form bean, and the user enters character data into the text field,
youre going to get an exception thrown before you (or the validator) ever
gets to see it.

When you call BeanUtils.copyProperties(destObject, srcObject), it will do
the type conversions for you. If the field names are the same, it will
typically handle it.

If youre using your own type that BeanUtils doesn't understand out of the
box, you can register a class that implements the Converter interface. This
tells copyProperties() how to convert it from a String. I do this quite a
bit with enumerations.


> -----Original Message-----
> From: Caroline Jen [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, June 17, 2006 10:48 PM
> To: user@struts.apache.org
> Subject: BeanUtils, Form Bean and POJO Bean
> 
> The Java "types" of the properties in my form bean sometimes 
> are not the same as those of the data fields in my database.
> 
> The request.getParameter(); always return a String.  I can 
> use the copyProperties() method of the BeanUtils to convert 
> all the String(s) read from the web page to proper Java 
> "types" in my form bean.
> 
> What do I do when the property type in my form bean does not 
> match the data field type in my POJO bean?
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection 
> around http://mail.yahoo.com 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 



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

Reply via email to