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.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Maintaining CheckBox status

Aatif Hasan
1 decade ago Jul 03, 2012 8:31am

Hi.. All,

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.!

Please anyone help me out or provide me any link.

Thanks in advance.!!

Aatif Hasan
1 decade ago Jul 03, 2012 10:33am

Yeah... I solved it. :)

Here is the following code snippet : -

Add boolean property In Bean Class-

1.) boolean isChecked = false;

public boolean isChecked() {
return isChecked;

public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
2.) Main Class-

// Create a container for the beans
final BeanItemContainer<BeanClass> beans = new BeanItemContainer<BeanClass>(

// 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.setVisibleColumns(new Object[] { "name", "energy" });

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.addListener(new Property.ValueChangeListener() {
public void valueChange(Property.ValueChangeEvent event) {

bean.setChecked(((Boolean) event.getProperty()
if (bean.isChecked()) {
} else {

return cb;

vl.addComponent(new Button("<", new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
System.out.println("Run back..");

vl.addComponent(new Button(">", new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
System.out.println("Move ahead..");


Last updated on Jul, 3rd 2012