Binding Grid to Entity

Hello, i am using vaadin 8 with wildfly 11.

In the Backend I have the following 3 Classes

  • Entity
  • EJB
  • DAO


@NamedQuery(name = Title.QUERY_GETALL, query = "SELECT c FROM Title c")
public class Title implements Serializable {

	private static final long serialVersionUID = 1L;
	public static final String QUERY_GETALL = "Title.GetAll";
	private Timestamp createAT;
	private Timestamp modifyAT;

	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;

	private String title;

	public int getId() {
		return id;

	public void setId(int id) { = id;

	public String getTitle() {
		return title;

	public void setTitle(String title) {
		this.title = title;

	protected void onCreate() {
		createAT = new Timestamp(System.currentTimeMillis());

	protected void onUpdate() {
		modifyAT = new Timestamp(System.currentTimeMillis());



public class TitleEJB implements TitleDAO {

	private EntityManager em;

	public Title create(Title title) {
		return title;

	public Title update(Title title) {
		return em.merge(title);

	public void remove(int id) {
		Title toBeDeleted = getTitle(id);

	public Title getTitle(int id) {
		return em.find(Title.class, id);

	public List<Title> getAllTitle() {
		return em.createNamedQuery(Title.QUERY_GETALL, Title.class).getResultList();


public interface TitleDAO {

	public Title create(Title title);
	public Title update(Title title);
	public void remove(int id);
	public Title getTitle(int id);
	public List<Title> getAllTitle();


In the Frontend I want now to bind the Entity of the Backend to a Vaadin Grid and make it editable:

public class TitleView02 extends VerticalLayout implements View {

	private Button add;
	private Set<Title> selected;
	private Title title;

	public TitleView02(TitleService service) {
		final List<Title> allTitles = service.getAllTitle();
		// Empty Grid, must add Columns to show by hand
		Grid<Title> grid = new Grid();


		grid.addColumn(title -> title.getTitle()).setCaption("-Titel-").setEditorComponent(new TextField(), Title::setTitle);

		add = new Button("+");
		add.addClickListener(event -> addRow(service, grid));

		HorizontalLayout tb = new HorizontalLayout(add);
	private void addRow(TitleService service, Grid<Title> grid) {
		int maxListPrio;
		Title title = new Title();

		 * Get max of ListPrio
		List<Title> list = service.getAllTitle();
		maxListPrio = 0;
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getListPrio() > maxListPrio) {
				maxListPrio = list.get(i).getListPrio();

		title.setListPrio(maxListPrio + 1);

		refreshGrid(grid, service);

	private void refreshGrid(Grid<Title> grid, TitleService service) {
		List<Title> list = service.getAllTitle();

The Grid is editable.
But the data are not saved in the Database.

What must i do, that the data are saved in the database?

I suggest creating your own dataprovider since it pulls data from backend, it should extend AbstractBackEndDataProvider.

Look at the example at this page :

At the bottom of the page, there is the example you are looking for.