简体   繁体   English

Apache Wicket:隐藏/显示后textarea丢失内容

[英]Apache Wicket: textarea lose content after hide/show

I have wicket form with checkbox and textarea. 我有带复选框和textarea的检票口形式。 I need to hide and show textarea when checkbox value changed. 复选框值更改时,我需要隐藏和显示textarea。

This is my implementation: 这是我的实现:

private class EditCommentForm extends Form {

    private TextArea applyToAllArea;
    private boolean addToAll;

    // some code here

    public EditCommentForm(String id) {
        super(id);
        applyToAllArea = new TextArea<>("applyToAllArea", Model.of(""));
        applyToAllArea.setVisible(addToAll);
        applyToAllArea.setOutputMarkupId(true);
        applyToAllArea.setOutputMarkupPlaceholderTag(true);
        add(applyToAllArea);

        CheckBox addToAllCheckbox = new AjaxCheckBox("addToAll", new PropertyModel<>(this, "addToAll")) {
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                applyToAllArea.setVisible(addToAll);
                target.addComponent(applyToAllArea);
            }
        };
        addToAllCheckbox.setVisible(documents.size() > 1);
        add(addToAllCheckbox);
        // some code here
    }

    private boolean isAddToAll() {
        return addToAll;
    }

}

When I type some information into textarea and then click on checkbox twice(hide and show textarea) my typed information lose. 当我在textarea中键入一些信息,然后两次单击复选框(隐藏并显示textarea)时,我键入的信息丢失。

So, how I can save typed information without form submit? 那么,如何在不提交表单的情况下保存键入的信息?

Wicket version 1.4.20 Wicket版本1.4.20

As @bert explained the problem is that the content of the textarea is not saved anyhow and after repaint Wicket uses the current model at the server side which is empty. 正如@bert解释的那样,问题在于文本区域的内容无论如何都不会保存,并且在重新绘制后,Wicket在服务器端使用了空的当前模型。

An easy solution is to add new AjaxFormComponentUpdatingBehavior("onblur") to the textarea so that it saves its content when the user moves to another element in the page. 一个简单的解决方案是将new AjaxFormComponentUpdatingBehavior("onblur")到文本区域,以便在用户移动到页面中的另一个元素时保存其内容。

I'd suggest you to upgrade to at least 1.4.22. 我建议您至少升级到1.4.22。 It has few security related fixes compared to 1.4.20. 与1.4.20相比,它几乎没有与安全相关的修复程序。

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

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