如何清除onValidate()引起的class(form)相关的错误?

How to clear errors related to class (form) caused by onValidate()?

在 wicket 1.4 中,我曾经以特定形式清除由 onValidate() 方法引起的错误。不幸的是,在迁移到 wicket 6 之后,方法执行的顺序发生了变化,或者我的代码编写得不好。所以我有 ajax 按钮,类似于:

    final AjaxFallbackButton submitButton = new AjaxFallbackButton(PREFIX + ".submit", new I18nModel(title), panelForm) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            // submit method
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            addPanel.setProcessingEnabled(true);
        }
    };

    submitButton.add(new AjaxFormSubmitBehavior(panelForm, "onclick"){
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            addPanel.setProcessingEnabled(false);
            super.onEvent(target);
        }
    });

addPanel 指向 class,其中包含我要清除错误的表单。所以在这个class中我添加了这样的表格:

    panelForm = new Form<B>("panelForm", new PrefixedCompoundModel<B>(getDefaultModelObject(), PREFIX)) {
        @Override
        protected void onValidate() { 
            super.onValidate();
           if (!processingEnabled) {
                Session.get().getFeedbackMessages().clear(new ContainerFeedbackMessageFilter(this));
            }                              
        }

        @Override
        protected void onError() {
            UiUtils.refresh(panelForm);
        }
    };

变量 processingEnabled 默认为真。我只是在单击上面的 ajax 按钮时才更改它。它过去常常先处理我的行为,然后再处理上面表格中的 onValidate。现在它是:onValidate -> onError(panelForm) -> behavior -> onValidate -> onError(panelForm) -> onError(button)。我想在 onValidate 之前传递 processingEnabled 参数,或者在 onError 方法中清除与此表单相关的所有错误。感谢反馈。

Session.get().getFeedbackMessages() 仅在会话中为您提供反馈消息 - 但由于 Wicket 6 反馈消息与其组件一起存储:

https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+6.0#MigrationtoWicket6.0-FeedbackStorageRefactoring