I’ll be thankful if someone could help me. Actually i’m using Vaadin Pagination(
PagedTable
) and
BeanItemContainer . I am able to add a column of
CheckBox and page navigation is also working like a charm.
But the problem is i’m unable to
Maintain the Status of CheckBoxes . As i check any CheckBox and navigate to the next page the CheckBoxes are
getting unchecked automatically while returning back to the previous page. I tried a lot to save the status of CheckBoxes in the been class by adding “isChecked” boolean property but still no luck.
Paged Table images with2 pages are attached below.!
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
}
2.) Main Class-
// Create a container for the beans
final BeanItemContainer beans = new BeanItemContainer(
BeanClass.class);
// Use the name property as the item ID of the bean
// ArrayList<BeanClass> beanlist = new ArrayList<BeanClass>();
// Add some beans to it
beans.addBean(new BeanClass("Mung bean", 1452.0));
beans.addBean(new BeanClass("Chickpea", 686.0));
beans.addBean(new BeanClass("Lentil", 1477.0));
beans.addBean(new BeanClass("Common bean", 129.0));
beans.addBean(new BeanClass("Soybean", 1866.0));
/* This set contains the ids of the "selected" items */
// Bind a table to it
final PagedTable pgtable = new PagedTable("Beans of All Sorts");
pgtable.setContainerDataSource(beans);
pgtable.setVisibleColumns(new Object[] { "name", "energy" });
pgtable.setPageLength(3);
pgtable.addGeneratedColumn("selected", new Table.ColumnGenerator() {
@SuppressWarnings({ "serial", "serial" })
public Object generateCell(Table source, final Object itemId,
Object columnId) {
final BeanClass bean = (BeanClass) itemId;
// final BeanClass entity = (BeanClass) itemId;
// boolean selected = false;// =
// selectedItemIds.contains(itemId);
final CheckBox cb = new CheckBox();
cb.setImmediate(true);
cb.addListener(new Property.ValueChangeListener() {
public void valueChange(Property.ValueChangeEvent event) {
bean.setChecked(((Boolean) event.getProperty()
.getValue()));
}
});
if (bean.isChecked()) {
cb.setValue(true);
} else {
cb.setValue(false);
}
return cb;
}
});
vl.addComponent(pgtable);
vl.addComponent(new Button("<", new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
System.out.println("Run back..");
pgtable.previousPage();
}
}));
vl.addComponent(new Button(">", new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
System.out.println("Move ahead..");
pgtable.nextPage();
}
}));