【问题标题】:Error with validate() in AbstractFormValidator WicketAbstractFormValidator Wicket 中的 validate() 错误
【发布时间】:2012-02-15 01:30:29
【问题描述】:

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

为什么找不到错误信息?

【问题讨论】:

    标签: java forms validation wicket validationerror


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-10
      • 2018-06-11
      • 2021-08-02
      • 1970-01-01
      • 2012-11-04
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      相关资源
      最近更新 更多