Question

I got one column with checkboxes, it is generated by column generator, how can i set them all checked ?

Thanks.

Was it helpful?

Solution 2

When you generate the column mark the checkboxes.

cb.setData("x");

Then:

Iterator<Component> iterator = table.iterator();
while ( iterator.hasNext() ) {
  Component c = iterator.next();
  if (c instanceof AbstractField) {
    AbstractField<Object> af = (AbstractField<Object>) c;
    if ("x".equals(af.getData())) {
      af.setValue(true);
    }
  }
}

(The code is not tested.)

OTHER TIPS

Here is a dummy example:

public class CheckBoxColumnGenerator implements Table.ColumnGenerator {

    @Override
    public Object generateCell(Table source, Object itemId, Object columnId) {
        Property<?> prop = source.getItem(itemId).getItemProperty(columnId);
        return new CheckBox(null, prop);
    }
}

...

Table table = new Table();
table.addContainerProperty("checkbox", Boolean.class, null);
table.addContainerProperty("label", String.class, null);
table.addItem(new Object[] { true, "row#1" }, 1);
table.addItem(new Object[] { false, "row#2" }, 2);
table.addItem(new Object[] { true, "row#3" }, 3);
table.addItem(new Object[] { false, "row#4" }, 4);
table.addGeneratedColumn("checkbox", new CheckBoxColumnGenerator());

Then:

for (Object itemId : table.getItemIds()) {
    table.getItem(itemId).getItemProperty("checkbox").setValue(true);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top