Hi Craig,

(I sent about an hour ago a message to the list, that seems
 to have been lost somewhere. I've just resend it. In this
 message, I've tried to explain my point of view, which is
 similar to what you've written below. I've added some short
 inline comments - please read my other mail for a more
 detailled reasoning.)
 
>> [...]

> It is a side effect of what is really happening.

> The browser has no real clue that the field is an integer field -- it just
> thinks there is text.  Therefore, what it sends as input for an empty input
> field is a zero-length string, which (unfortunately) the BeanUtils populate
> method treats as a zero when setting an integer field.

Yes, I've tracked it down to populate too. I've seen that all number
conversions methods - ie. convert{Int,Float,Double...) follow the same
pattern...

private static TYPE convertTYPE(String value) {
        try {
            return (new TYPE(value));
        } catch (NumberFormatException e) {
            return (new TYPE(0.0));
        }
    }

I would think, that they should instead do
    
private static TYPE convertTYPE(String value) {
        if (value != null && value.length() > 0) {     // like JSP-spec
                try {
                    return (new TYPE(value));
                } catch (NumberFormatException e) {}
        }
        return null;
    }
}

However, I'm not sure, if such a change would cause undesired side-effects
(I'm especially unsure, what this change means to native number type
 properties like int, double...)

Also, I think the convertBoolean has a similar problem. (Any parameters will
be converted to false, if they're missing, unrecognized or syntactically
incorrect).

> It might make sense to skip calling the setIntProperty() field at all if the
> input is a zero-length string.  JSP follows this rule when you specify
> something like <jsp:setProperty name="beanname" property="*"/>, so this
> would be more consistent with JSP as well.

Yes, that's exactly what I wrote in my previous posting :)

Am I right, that I could write my own BeanUtils (together with a slightly
modified ActionServlet) if the majority of struts-users doesn't share my
opinion ?

Matthias                        (mailto:[EMAIL PROTECTED])


Reply via email to