I have a Wicket text box that contains an integer value
currentValueTextField = new TextField<IntParameter>("valueText", new PropertyModel<IntParameter>(model, "value"));
I attach a special validator to it, as shown below.
currentValueTextField.add(new IntegerValidator());
Validator class
class IntegerValidator extends AbstractValidator<IntParameter> {
private static final long serialVersionUID = 5899174401360212883L;
public IntegerValidator() {
}
@Override
public void onValidate(IValidatable<IntParameter> validatable) {
ValidationError error = new ValidationError();
if (model.getValue() == null) {
AttributeAppender redOutline = new AttributeAppender("style", new Model<String>("border-style:solid; border-color:#f86b5c; border-width: 3px"), ";");
currentValueTextField.add(redOutline);
currentValueTextField.getParent().getParent().add(redOutline);
validatable.error(error);
}
}
}
However, if I do not find anything in the text field, my method is onValidate()not called.
What is the recommended way to check for null values ββin this case? I would also like to do a range check on the entered value.
source
share