gpt4 book ai didi

java - AbstractFormValidator Wicket 中的 validate() 错误

转载 作者:行者123 更新时间:2023-11-30 04:54:38 24 4
gpt4 key购买 nike

我尝试向 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.

为什么找不到错误信息?

最佳答案

这是因为您应该提供一个属性键,允许 Wicket 在组件/页面/应用程序的属性包中找到正确的错误消息。

关于java - AbstractFormValidator Wicket 中的 validate() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8942161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com