AbstractFormValidator Wicket 中的 validate() 错误
我尝试向 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.
为什么找不到错误消息?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您应该提供一个属性键,允许 Wicket 在组件/页面/应用程序的属性包中找到正确的错误消息。
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.