lukaszrys
lukaszrys

Reputation: 1796

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

In wicket 1.4 I used to clear errors that were caused by onValidate() method in specific form. Unfortunetly after migrating to wicket 6 order of method execution has changed or my code was has been written poorly. So I have ajax button, similar to this:

    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);
        }
    });

The addPanel is pointing at class that contains form where I want to clear errors. So in this class I'm adding form like this:

    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);
        }
    };

Variable processingEnabled is true by default. I was only changing it when above ajax button has been clicked. It used to go first to my behavior and then to onValidate in form above. Right now it goes: onValidate -> onError(panelForm) -> behavior -> onValidate -> onError(panelForm) -> onError(button). I would like to pass processingEnabled argument before onValidate or clear all errors related to this form in onError method. Thanks for feedback.

Upvotes: 0

Views: 739

Answers (1)

svenmeier
svenmeier

Reputation: 5681

Session.get().getFeedbackMessages() gives you the feedback messages in the session only - but since Wicket 6 feedback messages are stored along with their components:

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

Upvotes: 1

Related Questions