复选框在wicket中没有取消选中

时间:2014-07-07 07:23:28

标签: wicket wicketstuff

我有一个检查组,并且在组中选中一个复选框,我想获取所选/选中复选框的数量。
通过以下代码,我可以获得所选数量的复选框,但在取消选中或删除选择时,我看到它仍处于选中状态。
示例:我现在选择了2,我选择了2个字符串 现在我取消选中一个复选框,即使现在我选择了2个字符串。虽然我希望检查一个字符串。

代码如下:

final CheckGroup myGroup = new CheckGroup("group", new ArrayList()) {
    @Override
    protected Collection<String> convertValue(String[] values) throws ConversionException {
        Collection<String> myCollection = super.convertValue(values);
        checkedString.addAll(myCollection);
        HashMap<Integer, String> myTempList = new HashMap<Integer, String>();
        for (String myString : checkedString) {
            myTempList.put(myString.getSystemId(), myString);
        }
        checkedString.clear();
        for (Entry<Integer, String> myEntry : myTempList.entrySet()) {
            checkedString.add(myEntry.getValue());
        }
        return checkedString;
    }

    @Override
    protected void onSelectionChanged(Collection newSelection) {
        newSelection = checkedString;
    }

    @Override
    protected boolean wantOnSelectionChangedNotifications() {
        return true;
    }
};


add(myForm);
myForm.add(myGroup);

1 个答案:

答案 0 :(得分:0)

向您的组件添加行为

sampleChckbox.add(new AjaxFormComponentUpdatingBehavior("onclick"){
  @Override
  protected void onUpdate(AjaxRequestTarget target) {
 //perform your operation here       
}

此方法将在“onClick”事件上触发Ajax请求;这将在运行时更新后端逻辑

编辑

非常特定于CheckGroup类使用AjaxFormChoiceComponentUpdatingBehavior

AjaxFormChoiceComponentUpdatingBehavior是与CheckGroupRadioGroup一起使用的行为。如果您在AjaxFormComponentUpdatingBehavior事件中使用onchange,则会在IE中遇到this bugAjaxFormChoiceComponentUpdatingBehavior CheckCheckGroup中的每个CheckBox正确处理AjaxCheckBox

作为附注,Igor在该邮件中说明的是,Check可以替换为AjaxCheckBox,而不是CheckBoxAjaxFormComponentUpdatingBehavior("onclick")只是{{1}}的便捷子类,{{1}},adding onclick event handlers显示。