简体   繁体   English

Apache wicket:如何显式更新表单?

[英]Apache wicket: how to update form explicitly?

I have an issue with ListView and validation on page. 我在页面上有ListView和验证问题。

I have ListView, and underneath it I have TextField, where the user can enter values. 我有ListView,在它的下面有TextField,用户可以在其中输入值。 I have "publish" and "draft save" buttons on my page. 我的页面上有“发布”和“草稿保存”按钮。 Publish is a button, where popup (ModalWindow) is shown, where user should confirm entered data. 发布是一个按钮,其中显示弹出窗口(ModalWindow),用户应在其中确认输入的数据。 Save draft is saving without confirmation. 保存草稿即保存而未确认。 Both are SecuredAjaxLink objects. 两者都是SecuredAjaxLink对象。

When a user enters data in TextField, it is saved in ListView, but the whole list isn't updated as user should press button Add below. 当用户在TextField中输入数据时,该数据将保存在ListView中,但整个列表不会更新,因为用户应按下面的“添加”按钮。 This is ok. 还行吧。

The problem is, that I have business validation, where user entered information is checked for some rules. 问题是,我进行了业务验证,其中检查了用户输入的信息中的某些规则。 When validation failing all fields (containing wrong info) are highlighted with css. 验证失败时,所有字段(包含错误的信息)将以css突出显示。 To explicitly add value from TextField to ListView i'm doing 要将值从TextField显式添加到ListView中,我正在做

target.addComponent(form);

This is performed before data goes to validation. 这是在数据进行验证之前执行的。 So all fields are updated. 因此,所有字段均已更新。 This works fine for publish button (with confirmation ModalWindow), but doesn't work with the link without popup. 对于发布按钮(带有确认ModalWindow),此方法工作正常,但在没有弹出窗口的情况下不适用于链接。 As I understand there is something wrong with lifecycle of target, but I'm stuck with it. 据我了解,目标的生命周期存在问题,但我坚持下去。

Maybe someone had something similar or know the answer? 也许有人有类似的东西或知道答案?

How can I update the page without using popup? 如何在不使用弹出窗口的情况下更新页面?

Here is the code: Draft link: 以下是代码:草稿链接:

add(new SecuredAjaxSubmitLink(LinkNames.savelaterLink.toString(), form,
                RoleController.CONTROLLER.getAccessController()) {
            @Override
            public void onSubmit(AjaxRequestTarget target, Form form) {
                target.addComponent(form);
                insert(appl, false, form, target, new MainMenu(getString("accept.application.draft.success.message")), trail, checkbox);
            }

Publish link: 发布链接:

add(new CustomAjaxSubmitLink(LinkNames.submitLink.toString(), form,
                RoleController.CONTROLLER.getAccessController()) {
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form form) {
                target.addComponent(form);
                publishPopup.show(target);
            }
        });

publishPopup.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
            public void onClose(AjaxRequestTarget target) {
                if (ApplicationInsertActionPanel.this.getSelectedAction() != null
                        && ApplicationInsertActionPanel.this.getSelectedAction().equals(Action.CONFIRM)) {
                    insert(appl,
                            true,
                            form,
                            target,
                            new MainMenu(ApplicationInsertActionPanel.this
                                    .getString("accept.application.publish.success.message")), trail, checkbox);
                }

            }
        });

I've added 我已经添加

@Override
            protected void onError(final AjaxRequestTarget target, Form<?> form)
            {
                super.onError(target, form);
                target.addComponent(form);

to my draft link, but still page is not fully updated. 到我的草稿链接,但页面仍未完全更新。 I suppose it is because target's lifecycle is not ended, like it is ending when i'm using popup window. 我想这是因为目标的生命周期没有结束,就像当我使用弹出窗口时结束一样。 Popup window is opening "new page" and old target can be updated, but when i'm not using popup, the page stays like it was. 弹出窗口正在打开“新页面”,并且可以更新旧目标,但是当我不使用弹出窗口时,页面保持原样。 So now i'm thinking about some workaround to end target lifecycle. 因此,现在我正在考虑一些解决方案,以终止目标生命周期。 I was thinking about transparent popup window without any functionality, but is really very dirty solution. 我当时在考虑没有任何功能的透明弹出窗口,但实际上是非常肮脏的解决方案。

Any ideas? 有任何想法吗? Thanks! 谢谢! } }

My english isnt so well, and i dont totally understand you Post. 我的英语不太好,我也不完全了解您。 is it: type word in Textfield --> one of those submit buttons --> word appears on listview? 是:在“文本字段”中输入单词->这些提交按钮之一->单词出现在列表视图中? if you want to Validate the input why dont you use a class that inherits from IValidator.class 如果要验证输入,为什么不使用从IValidator.class继承的类

and if you want to update your form you can add a updatebehaviour to your form 如果您想更新表单,可以向表单添加更新行为

final AjaxFormSubmitBehavior            formbehavior    = new AjaxFormSubmitBehavior("onChange") {
    @Override
    protected void onError(AjaxRequestTarget arg0) {
        arg0.add(getForm());
    }

    @Override
    protected void onSubmit(AjaxRequestTarget arg0) {
        arg0.add(getForm());
    }
};

then you can add this behaviour to your form or extend it to your needs 那么您可以将此行为添加到表单中或扩展到您的需求

form.add(formbehavior)

i dont know if your problem is somehow related to my answer, but i suppose that you wanted to know how to update your form without loading the page new. 我不知道您的问题是否与我的答案有关,但我想您想知道如何在不加载新页面的情况下更新表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM