Wicket 6 到 8 升级:RadioGroup.onSelectionChanged() 替换 [英] Wicket 6 to 8 upgrade: RadioGroup.onSelectionChanged() replacement

查看:18
本文介绍了Wicket 6 到 8 升级:RadioGroup.onSelectionChanged() 替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们继承了使用 Wicket 6 的大型代码库,其中我们有一个 RadioGroup 首选联系人类型选择(短信、电子邮件等).当为 SMS 选择 Radio 时,电话号码的 TextField 可见,电子邮件等也是如此.

We have inherited a large code base that uses Wicket 6 where we have a RadioGroup of preferred contact type choices (SMS, e-mail, etc). When a Radio for SMS is selected, a TextField for phone number is made visible, same for e-mail and so on.

这是通过为每个Radio 添加一个用于onclick"事件的AjaxEventBehavior 来实现的.onEvent(AjaxRequestTarget) 方法调用 RadioGroup.onSelectionChanged() 并更新每个 TextField 的可见性:

This has been implemented by adding an AjaxEventBehavior for "onclick" event to each Radio. The onEvent(AjaxRequestTarget) method calls RadioGroup.onSelectionChanged() and updates the visibility of each TextField:

radioSms = new Radio<>("sms", ...);
radioEmail = new Radio<>("email", ...);
radioGroup = new RadioGroup<>("contactGroup");
radioGroup.add(radioSms)
          .add(radioEmail)
          .add(textFieldSms)
          .add(textFieldEmail);
radioSms.add(new OnClickEventBehavior());
radioEmail.add(new OnClickEventBehavior());

...

private class OnClickEventBehavior extends AjaxEventBehavior {
    protected OnClickEventBehavior() {
        super("onclick");
    }

    @Override
    protected void onEvent(AjaxRequestTarget target) {
        radioGroup.onSelectionChanged();
        updateTextFieldVisibilities();
        target.add(form);
    }
}

我们的问题是我们必须升级到 Wicket 8,onSelectionChanged() 方法已从 RadioGroup 中删除,我们找不到任何关于可能的替代品的文档.从 Wicket 6 JavaDocs 的两行之间阅读,我觉得甚至不应该手动调用 onSelectionChanged() 方法,因为文档只说明在选择新选项时调用."以被动形式.

Our problems are that we have to upgrade to Wicket 8, the onSelectionChanged() method has been removed from RadioGroup and we can not find any documentation about a possible replacement. From reading between the lines of Wicket 6 JavaDocs, I get the feeling that the onSelectionChanged() method shouldn't even be called manually, since the docs only state "Called when a new option is selected." in a passive form.

我有问题:

  1. 我们的祖先是否通过手动调用 onSelectionChanged() 来滥用 Wicket API?
  2. Wicket 8 中是否有 RadioGroup.onSelectionChanged() 的替代品?
  3. 实现第一段中描述的功能的正确方法是什么?
  1. Did our ancestors abuse the Wicket API by calling onSelectionChanged() manually?
  2. Is there a replacement for RadioGroup.onSelectionChanged() in Wicket 8?
  3. What is the correct way of implementing the functionality described in the first paragraph?

推荐答案

需要咨询迁移页面https://cwiki.apache.org/confluence/x/E7OnAw

新方法是:

// Wicket 8.x
new CheckBox("id", model).add(new FormComponentUpdatingBehavior() {
    protected void onUpdate() {
        // do something, page will be rerendered;
    }

    protected void onError(RuntimeException ex) {
        super.onError(ex);
    }
});

这篇关于Wicket 6 到 8 升级:RadioGroup.onSelectionChanged() 替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆