我尝试向 DateTextField 添加一些验证,如下所示:
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);
验证工作绝对正常,但错误消息的输出如下所示:
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.
为什么找不到错误信息?