1

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

为什么找不到错误信息?

4

1 回答 1

2

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

于 2012-01-20T13:57:02.280 回答