[英]Wicket Retrieving A CheckGroup's model when clicking a checkbox
I have a form with a checkbox column. 我有一个带有复选框列的表单。
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);
Now what I would want is to update a form whenever the number of selected objects change : 现在,我想要的是每当所选对象的数量发生变化时更新表单:
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
}
}));
Is there an easy way to achieve this with Wicket?? 有没有一种简单的方法可以用Wicket实现呢?
Add a AjaxFormChoiceComponentUpdatingBehavior to your checkgroup. 将AjaxFormChoiceComponentUpdatingBehavior添加到您的检查组。 The ajax will trigger everytime a check in your group is clicked. 每次单击组中的检查时,ajax都会触发。
myObjectGroup.add(new AjaxFormChoiceComponentUpdatingBehavior()
{
@Override
protected void onUpdate(AjaxRequestTarget target)
{
//update form elements
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.