Fundatemtal misunderstanding of varnish or just doing it wrong?

Hello Folks,

I just doing my first steps with vaadin.

I was able to populate a list with data ouf of my beans:

		BeanItemContainer<Student> c = new BeanItemContainer<Student>(Student.class);
		for (Student s : this.studentBean.getAll()) {

And I was able to make a form ouf of this. The form is populated with the data of the selected item in the table.

The problem I am facinc is that the changed data do not arrive in the database.
My form has a submit / commit-Button, but is there any magic needed that the data arrive in the database?

Thanks in advance!

I think I have solved my problem.

Using this code in the Eventhandler of the ClickEvent on the Button:

		c.addListener(new ClickListener() {
			private static final long serialVersionUID = 4768729254838905078L;

			public void buttonClick(ClickEvent event) {
				BeanItem s = (BeanItem) studentList.getItem(studentList.getValue());
				studentBean.modify((Student) s.getBean());

Is this the best solution or is it as dirty as i think?


Hello Björn,

you have to use a addListener to handle the save part when the user clicks on the save button,
that’s correct.

How you then persist back the changes from the Bean to the database depends on your persistence layer.

BTW: I don’t see what would be dirty about this… :wink:


So what is each step here doing?

If you are using a BeanItemContainer, all it handles is the in-memory processing, so your commit logic needs to save the data in one way or another. You can to this where you call commit(), or you could even override the Form.commit() method.

Some other containers are more directly connected to a database and perform updates when an item or its property is modified using the Item and Property interfaces as Form does - but they cannot listen to direct changes to the underlying bean.

You could get rid of the casts by using a BeanItemContainer and keeping a reference to it, fetching the item from it rather than from the list. That way, getItem(…) returns a BeanItem, and its getBean() returns a Student.