0
我有一個帶有複選框列的表單。檢票單擊複選框時檢索CheckGroup的模型
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實現這一目標?