I tried to add some validations to DateTextField as follows:
IFormValidator validator = new AbstractFormValidator() {
public FormComponent<?>[] getDependentFormComponents() {
return new FormComponent[] { dateTextField };
}
public void validate(Form<?> form) {
Date date = (Date) dateTextField.getConvertedInput();
if(date == null){
error(getDependentFormComponents()[0],"Date of Collection is empty.");
}
else{
if (date.before(getTodayDate(Boolean.TRUE))){
error(getDependentFormComponents()[0],"The range of the Date of Collection is invalid.");
}
}
}
};
form.add(validator);
The validations are working absolutely fine but the output of error message appeared as below:
Could not locate error message for component: CreatePrintingJob$3@form:dateOfCollection and error: [ValidationError message=[null], keys=[Date of Collection is empty., CreatePrintingJob$4], variables=[[label0=dateOfCollection],[name0=dateOfCollection],[input0=]]]. Tried keys: dateOfCollection.Date of Collection is empty., Date of Collection is empty., dateOfCollection.CreatePrintingJob$4, CreatePrintingJob$4.
Why could not the error message be located?
It is because you are supposed to give a property key allowing Wicket to find the correct error message in the property bundle of your component/page/application.