On 01 Apr 2011, at 20:56, Daniel Neugebauer wrote:
> BTW an empty string (that's not null) is a string nevertheless. Following the
> argument that an unchecked (false) checkbox should be regarded as valid if it
> is required, an empty string should be accepted as a valid input as well.
I don't see why you would think that. setRequired(true) means, "You must
provide a value for this component's model". An empty String and a null String
mean the same thing (since you cannot input a null String); in both instances,
it's the user saying: "I have no value for this". Hence, it makes perfect
sense that the setRequired(true) fails validation on an empty text field.
Contrary to a text field, an unchecked checkbox does not mean: "no value". It
means: "Off". As though I'd write "false" in my text field.
If the web application asks me whether I want to gift-wrap my purchase, leaving
the box unchecked does not mean I can't or don't want to make up my mind. It
means I do not want it gift wrapped. It's me saying: "No."
> I've just tested it with Wicket 1.4 and actually both of the following
> TextFields validate to a failed state:
>
> TextField tf1 = new TextField("text1", new PropertyModel<String>(this,
> "test1"));
> tf1.setRequired(true);
> tf1.setConvertEmptyInputStringToNull(false);
> form.add(tf1);
>
> TextField tf2 = new TextField("text2", new PropertyModel<String>(this,
> "test2"));
> tf2.setRequired(true);
> tf2.setConvertEmptyInputStringToNull(true);
> form.add(tf2);
>
Regardless, setConvertEmptyInputStringToNull is not relevant during
checkRequired. It is only used by the developer to say, if the user doesn't
enter any characters, make my model object null instead of an empty string.
checkRequired checks Strings.isEmpty(), which is perfectly sensible (ref. the
first paragraph of this email).
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]