The problem you are facing is related to the way Wicket works. First it converts input text into a model object and then it performs validation.
Thus, you have to use RangeValidator instead of StringValidator
IModel<Integer> model =
new PropertyModel<Integer>(personModel, "age");
Component ageField = new TextField<Integer>("age", model);
add(ageField).add(RangeValidator.<Integer>range(0, 99));
Note I've changes Long
to Integer
as I believe saving age as Long
is not practical.
Also note that link to NumberValidator is for Wicket 1.4, while you are using Wicket 6. Wicket 6 is a large API change comparing to previous versions.