Reputation: 1729
I have a class that implements the IValidator
. I add this validator class to my TextField
, and the overrided method validate(Invalidatable<T>)
is called. However, if the TextField
is empty, the method is not called, and the validation does not occurs. Why is this happening? Is this expected behavior?
Validator Class
public class CorporateNameValidator implements IValidator<String> {
private static final String ERROR_EMPTY = "Error";
@Override
public void validate(IValidatable<String> validatable) {
//Method not called when TextField has blank value.
final String name = validatable.getValue();
info("NAME: " + name);
}
}
Instantiating TextField
corporateNameInput = new TextField<String>(CORPORATE_NAME_INPUT_ID, new PropertyModel<String>(this, ""));
Setting TextField Properties
corporateNameInput.add(new CorporateNameValidator());
corporateNameInput.setOutputMarkupPlaceholderTag(true);
And then I add the TextField to the Form.
Upvotes: 2
Views: 2862
Reputation: 3682
From the JavaDoc of IValidator
:
Interface representing a validator that can validate an
IValidatable
object.Unless the validator implements the
INullAcceptingValidator
interface as well, Wicket will not passnull
values to theIValidator#validate(IValidatable)
method.
It is as designed, and you should implement INullAcceptingValidator
instead.
Upvotes: 11