gpt4 book ai didi

java - 如何清除onValidate()引起的类(表单)相关错误?

转载 作者:行者123 更新时间:2023-12-01 11:29:03 25 4
gpt4 key购买 nike

在 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)中,我添加了如下形式:

    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默认为true。我只是在单击上面的 ajax 按钮时才更改它。它曾经首先转到我的行为,然后转到上面表单中的 onValidate。现在是:onValidate -> onError(panelForm) -> behavior -> onValidate -> onError(panelForm) -> onError(button)。我想在onValidate之前传递processingEnabled参数,或者清除onError方法中与此表单相关的所有错误。感谢您的反馈。

最佳答案

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

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

关于java - 如何清除onValidate()引起的类(表单)相关错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30572362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com