If you look at the Boolean Converter as shown below, you will
find an empty string will be converted to false if useDefault is true.
if (stringValue.equalsIgnoreCase("yes") ||
stringValue.equalsIgnoreCase("y") ||
stringValue.equalsIgnoreCase("true") ||
stringValue.equalsIgnoreCase("on") ||
stringValue.equalsIgnoreCase("1")) {
return (Boolean.TRUE);
} else if (stringValue.equalsIgnoreCase("no") ||
stringValue.equalsIgnoreCase("n") ||
stringValue.equalsIgnoreCase("false") ||
stringValue.equalsIgnoreCase("off") ||
stringValue.equalsIgnoreCase("0")) {
return (Boolean.FALSE);
} else if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(stringValue);
}
Jing
Netspread Carrier
http://www.netspread.com
----- Original Message -----
From: "Michael Ruppin" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Friday, August 22, 2003 11:03 AM
Subject: [FRIDAY] BeanUtils.populate and Booleans
> I know, I know, never use anything but Strings in an
> ActionForm to be populated from the request. I guess
> this is the same old argument for that.
>
> I recently thought it might be convenient to use a
> Boolean, and it worked fine, until I re-used the Form
> for a query jsp where this property was NOT
> represented by a checkbox (Of course, I had to change
> reset() to leave the property null instead of
> defaulting false when "mode=query" is in the request).
> BeanUtils.populate does clearly specify that it only
> handles setters for String, boolean, int, long, float,
> and double. Still, I was surprised to learn that when
> an empty string was submitted for this property in the
> request, my Boolean was set to false.
>
> m
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.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]