yep, thats exactly the idea. we dont have to deprecate RequiredTextField, it can just call setRequired(true) in the constructor, its not doing much more then that now.

-Igor


On 2/27/06, Johan Compagner <[EMAIL PROTECTED]> wrote:
so FormComponent:
public final void validate()
    {
        final int size = validators_size();
        for (int i = 0; i < size; i++)
        {
            validators_get(i).validate(this);
        }
    }

would be come something like this:

public final void validate()
{
   if(!Strings.isEmpty(getInput()))
   {
        final int size = validators_size();
        for (int i = 0; i < size; i++)
        {
            validators_get(i).validate(this);
        }
    }
    else if(isRequired())
    {
        // set error message
    }
}

So validators then always can assume they really can do something.

Then RequiredTextField could be depricated..

Fine by me, i also think that require is more or less a property just like enabled or visible.

johan




On 2/27/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
im working on some form/validation stuff right now and it seems to me that it would be cleaner to remove the RequiredValidator and instead introduce a required property (flag) for a form component.

there are a couple of reasons why i think this is better:
1) our validators will be cleaner. currently our validators dont know if null is a valid value so we always first check if the value is empty, and then if its not run the validator. take a look at PatternValidator:107. with this change validators wont run when the field is empty.

2) it is useful for other components to know if the field is required or not.

what do you guys think?

so instead of add(new TextField("foo").add(RequiredValidator.getInstance())) it will be add(new TextField("foo").setRequired(true));

-Igor



Reply via email to