Editable table with BeanItemContainer

Hi

I’m trying to create an editable table with a backing Container implementation, but for some reason I cannot get the table to be editable.

I have a small example that shows the problem:

		Table table = new Table();
		
		table.addContainerProperty("myBoolean", Boolean.class, null);
		table.addContainerProperty("myString", String.class, null);
		
		
		BeanItemContainer<MyBean> container = new BeanItemContainer<MyBean>(MyBean.class);
		container.addBean(new MyBean().setMyBoolean(true).setMyString("first"));
		container.addBean(new MyBean().setMyBoolean(false).setMyString("second"));
		
		table.setContainerDataSource(container);
		table.setEditable(true);
		table.setImmediate(true);
		
		layout.addComponent(table);

The MyBean class code is as follows:

public class MyBean {
	private boolean myBoolean;
	private String myString;
	
	public MyBean() {
		super();
	}

	public boolean isMyBoolean() {
		return myBoolean;
	}

	public MyBean setMyBoolean(boolean myBoolean) {
		this.myBoolean = myBoolean;
		return this;
	}

	public String getMyString() {
		return myString;
	}

	public MyBean setMyString(String myString) {
		this.myString = myString;
		return this;
	}

}

Why is the table not editable?

/ Fredrik Ferm

I was having the same problem. Turned out I had forgot to put setters in my POJO. Without the setters in the POJO, the readOnly value of the property was being set to true by Vaadin.

Apparently, the same thing happens if the return type of the setter is not void. I experienced the same behavior you described when I had my setters return the POJO. Setting the return type to void fixed the problem.

Thanks Ross… I also had the same problem. It is solved by adding setters to the BeanType :slight_smile: