【问题标题】:Show button if input text field is not empty in Wicket如果 Wicket 中的输入文本字段不为空,则显示按钮
【发布时间】:2021-07-09 12:23:36
【问题描述】:

有输入文本字段和提交按钮。我想显示按钮文本字段不为空,否则按钮不可见。

            TextArea<String> textMessageField = new TextArea<>("textMessage", textMessageModel);
            Button submitBtn = new Button("saveReminderButton") {
                @Override
                protected void onConfigure() {
                    super.onConfigure();
                    String text = textMessageField.getModelObject();
                    setVisible(text != null && !text.isEmpty());
                }
            };

            textMessageField.add(new OnChangeAjaxBehavior() {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(submitBtn);
                }
            });
            submitBtn.setOutputMarkupId(true);

我正在尝试在onConfigure 中使用setVisible 方法,但它不起作用。我尝试改用setEnabled,它正在工作,但我需要与隐藏/显示按钮相同的功能

【问题讨论】:

  • 我总是为此覆盖 isVisble

标签: java wicket


【解决方案1】:

由于您使按钮不可见,因此您需要使用 submitBtn.setOutputMarkupPlaceholderTag(true); 而不是 submitBtn.setOutputMarkupId(true);

这很重要,因为没有setOutputMarkupPlaceholderTag(true) Wicket Wicket 将不会为此组件渲染任何内容。使用setOutputMarkupPlaceholderTag(true),它将呈现&lt;htmlElement id="someId"&gt;&lt;/htmlElement&gt;。这样,Wicket Ajax 就可以在 DOM 中找到它,并将其替换为可见的 HTML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    相关资源
    最近更新 更多