Editable Table - edit & save only subset of Bean's fields

Hi,

Can someone help me or point to example on how to solve my problem.

First I have a Table with Employee elements passed to it as BeanItems.

public class NewEmployeeTableComp extends VerticalLayout {
	public static final Object[] NATURAL_COL_ORDER = new String[]
 { "year", "firstname", "lastname" }; //not all properties of Employee class
	private Table table = new Table();

	private MyVaadinApplication app;

	private EmployeeFacade employeeFacade;

	public NewEmployeeTableComp() {
		initApp();
		this.employeeFacade = app.getEmployeeFacade();

		table.setSelectable(true);
		table.setImmediate(true);

		EmployeeBeanContainer container = new EmployeeBeanContainer();
		table.setContainerDataSource(container);
		container.populate(employeeFacade.getAll());


		table.setVisibleColumns(NATURAL_COL_ORDER);
		
		addComponent(table);

	}

	private final void initApp() {
		this.app = MyVaadinApplication.getInstance();
	}

	@SuppressWarnings("serial")
	private class EmployeeBeanContainer extends BeanItemContainer<Employee> {

		public EmployeeBeanContainer() {
			super(Employee.class);
		}

		public void populate(List<Employee> list) {
			for (Employee each : list) {
				addBean(each);
			}
		}
	}
}


What I want to achieve?

  • I want to edit Employee in each row, and then save only those that changed to the database.
  • Only subset of Employee properties should be editable (like year and firstname) - best option would be that after slecting row, year and firstname cells become editable TextFields.
  • Save should occurred after clicking Save button (not in code) to all changed elements OR elements selected (I guess either way works for me)

So I’ve got few questions?

  1. Is BeanItemContainer good choice for my Table?
  2. Can I add custom column to Table with BeanItems? I wonder if I can add Checkbox to each row and save to the DB only those Employees who have checkbox selected.
  3. How to make editable rows/cells in Table?
  4. How to get changed data and save it back to Employee entities in DB?