And to Rick's note, I should mention I never use copyProperties.. I "can" if I
was insane enough :o)
Rick Reumann <[EMAIL PROTECTED]> wrote: Paul Benedict wrote:
> 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.
Just be weary though, that BeanUtils can really by a major PAIN when you
have domain objects that have number wrapper data types (Integer,
Double, etc). BeanUtils has the VERY annoying behavior of converting
null Strings to 0 for those number types. I end up always have to make
Converters to deal with this and I really think BeanUtils should have a
release that makes this NOT the default behavior. (Possibly provide some
kind of extra param if you really want null to become 0).
Here's a test to demonstrate...
public class Test() {
public static void main(String[] args) {
Test test = new Test();
test.doTest();
}
private void doTest() {
FormBean form = new FormBean();
DomainBean bean = new DomainBean();
try {
BeanUtils.copyProperties(bean, form);
System.out.println("The string value of integer: "+
bean.getNumber() ); //0 !!!
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public class FormBean {
private String number;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
public class DomainBean {
private Integer number;
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.