protected void onError(AjaxRequestTarget target, IModel rowModel, WebMarkupContainer rowComponent) {
target.addComponent(feedback);
}
});
final DataGrid grid = new DataGrid("grid", dataSource, columns) {
@Override
public void onItemSelectionChanged(IModel item, boolean newValue) {
AjaxRequestTarget target = AjaxRequestTarget.get();
if (target != null) {
target.addComponent(removeSelected);
}
super.onItemSelectionChanged(item, newValue);
}
};
grid.setRowsPerPage(Integer.MAX_VALUE);
grid.setAllowSelectMultiple(true);
grid.setContentHeight(14, SizeUnit.EM);
grid.setSelectToEdit(false);
add(grid);
add(removeSelected = new AjaxLink<Void>("removeSelected") {
@Override
public void onClick(AjaxRequestTarget target) {
Collection<IModel> items = grid.getSelectedItems();
if (items.size() > 0) {
for (IModel model : items) {
Entry entry = (Entry) model.getObject();
dataSource.removeEntry(entry);
}
grid.resetSelectedItems();
dataSource.storeToPageParameters();
grid.markAllItemsDirty();
grid.update();
} else {
target.appendJavaScript("alert('" + getString("noItemsSelected") + "');");
}
}
@Override
public boolean isEnabled() {
return !grid.getSelectedItems().isEmpty();
}
});
}