AbstractFormValidator Wicket 中的 validate() 错误

发布于 2024-12-27 23:03:15 字数 1273 浏览 6 评论 0原文

我尝试向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

焚却相思 2025-01-03 23:03:15

这是因为您应该提供一个属性键,允许 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文