0

我有一个带有复选框列的表单。

ArrayList<MyObject> myObjectsList = // Load from database ...
ArrayList<MyObject> selectedObjects = new ArrayList<MyObject>();

Form form = new Form("my-form");

CheckGroup<MyObject> myObjectGroup = new CheckGroup<MyObject>("object-check-group", new AbstractReadOnlyModel() {
  @Override
  public Object getObject() {
    return selectedObjects;
  }
});

WebMarkupContainer container = new WebMarkupContainer("table-container");

DataView dataView = new DataView("table-body", new ListDataProvider<MyObject>(myObjectsList)) {
  public void populateItem(final Item item) {
    final MyObject myObject = (MyObject) item.getModelObject();
    item.add(new Check("check-box", item.getModel())); // Checkbox for each item
    // And a couple more columns
  }
};

container.add(dataView);
group.add(container);
form.add(group);
add(form);

现在我想要的是在所选对象的数量更改时更新表单:

item.add(new Check("check-box", item.getModel()).add(new AjaxEventBehavior("onclick") {
  @Override
  protected void onEvent(AjaxRequestTarget target) {
    selectedObjects = (ArrayList<MyGroup>) myObjectGroup.getModelObject(); // this does not work sadly :(
    // Update form elements
  }
}));

有没有一种简单的方法可以使用 Wicket 实现这一目标?

4

1 回答 1

5

将 AjaxFormChoiceComponentUpdatingBehavior 添加到您的检查组。每次单击您的组中的检查时,ajax 都会触发。

    myObjectGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() 
    {
        @Override
        protected void onUpdate(AjaxRequestTarget target) 
        {
            //update form elements  
        }         
    }); 
于 2013-02-26T11:55:21.530 回答