the whole refactor started because validators were doing a lot of repeitive
stuff.

for example lets say you have a textfield for a purchase quantity. you add
three validators to it, requred, min1) and checkinventory.

min(1) = { if (input==null) return; int i=typeconvertinput(); if (i<1)
error(); }
checkinventory() = { if (input==null) return; int i=typeconvert(); if
(i>getavailable()) error(); }

what do we notice...

both validators have input==null check because they will run whether or not
field is required or not. both validators have to perform typeconversion -
which is potentially an expensive operation.

so lets refactor type conversion into the formcomponent. great, but the
problem is we dont know if we have to convert a "" or not. so we also factor
out the required check.

the nice thing about it is that now our validators look like this

min(1) = { if (i<1) error(); }
checkinventory() = { if (i>getavailable()) error(); }

so now not every validator has to check for null, and type conversion is
only performed/checked once and in a single place.

-igor

On 8/8/07, David Leangen <[EMAIL PROTECTED]> wrote:
>
>
> I guess this was already discussed at some point on the dev list, but I
> couldn't find the thread.
>
> I'm just very curious about the motivation of deprecating
> RequiredValidator in favour of the setRequired method.
>
> Knowing how clever you devs are, I'm sure there's a good reason, but at
> first glace, to me the RequiredValidator seems like a more elegant
> solution...
>
>
> Would somebody mind explaining this decision, if you have the time?
>
>
> Thanks!
> Dave
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to