what version are you using?
RequiredValidator is gone in 1.3, let me try to explain the reason:
warning, below is a brain dump, so tread softly
it has to do with type-conversion and where it fits in the workflow of
validating the component
we want validators to work on properly converted types. so when you write a
MinIntValidator you should expect validatable.getvalue() to return an
integer, not a string that you then have to convert to the integer yourself.
the typical workflow for validating a form component is
check required, perform type conversion, run the rest of validators
the reason it has to be that way is that the only valid place to perform
type conversion is after you have checked if the component is required or
not, because you dont want to try to convert an empty string to a typed
object all the time - wheter it is valid or not.
if we do not do this then every validator you write has to do two things
before it can actually get to its job: check if the value is not-null and
perform any required type conversion. so every validator has to cope with
type conversion errors, etc.
we wanted to factor out type conversion out of validators, which also meant
factoring out the required check as well.
makes sense?
-igor
On 6/19/07, Jan Vermeulen <[EMAIL PROTECTED]> wrote:
Problem with all these solutions, is that we have to differentiate between
'RequiredValidators' and other validators, which means somehow we have to
know which ones to call when. Because now, there is just a list of
validators, added to the component, and they get called by Wicket. What
I'm
trying to say is that checking if a field is empty or not can be just a
validator task. Now, we can no longer simply plug that in as just another
validator.
I understand that it is handy not to have to check if a value is null, but
we're paying a price for this that might be higher than the gain ?
Jan.
igor.vaynberg wrote:
>
> or instead,
>
> maybe make that hibernatevalidator also be a behavior, and simply toggle
> component's setrequired in onattach
>
> -igor
>
>
> On 6/19/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
>>
>> i dont know about that. isvalid's contract is that it only returns
false
>> if there are error messages reported against the component.
>>
>> i think this would be simple enough
>>
>> class hibernatetextfield extends textfield {
>> valid() {
>> if (hibernaterequired()) {
>> if (Strings.isEmpty(getInput()[0])) {
>> error(new ValidationError().addMessageKey("Required"));
>> return;
>> }
>> }
>> super.validate();
>> }
>>
>> -igor
>
--
View this message in context:
http://www.nabble.com/Problem-with-latest-changes-in-FormComponent%3Avalidate%28%29-tf3945885.html#a11200959
Sent from the Wicket - Dev mailing list archive at Nabble.com.