Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
how to remove a row from the table
HI,
i added checkboxes to the table and a delete button to the layout.now the required items selected through checkbox should be deleted when i press delete button.i am getting all the item ids and written statements to read the checkbox and display whether it is true (checked).now i am not able to get that particular item id of a particular row which is checked .the moment the id of the checked item is got that particular item should be deleted.can anyone please help me how to get the item id of a particular selected row?can you please reply me soon?
You need to iterate all items in the table and check the corresponding checkbox state. A quick example:
public class TestcaseApplication extends Application {
private Table table;
@Override
public void init() {
setMainWindow(new Window("Test Application"));
getMainWindow().addComponent(table = new Table());
table.addContainerProperty("Checkbox", CheckBox.class, null);
table.addContainerProperty("String", String.class, null);
for (int i = 0; i < 10; i++) {
Object id = table.addItem();
table.getContainerProperty(id, "Checkbox").setValue(new CheckBox());
table.getContainerProperty(id, "String").setValue("row " + id);
}
getMainWindow().addComponent(
new Button("Delete checked", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// Can't delete while iterating the item ID collection,
// so we store the item ids and delete outside the loop
List<Object> toDelete = new ArrayList<Object>();
for (Object id : table.getItemIds()) {
// Get the checkbox of this item (row)
CheckBox checkBox = (CheckBox) table
.getContainerProperty(id, "Checkbox")
.getValue();
if (checkBox.booleanValue()) {
toDelete.add(id);
}
}
// Perform the deletions
for (Object id : toDelete) {
table.removeItem(id);
}
getMainWindow().showNotification(
"Removed " + toDelete.size() + " rows");
}
}));
}
}