BindValidationBinder.writeBean not updating bean

Building a POC using the Full Stack Starter. Everything is working quite well except the BeanValidationBinder is not updating the bean with the values from the form.

The code where the bean is set is fairly straight forward:

try { BeanValidationBinder<T> binder = getBinder(); binder.validate(); binder.writeBean(editItem); } catch (ValidationException e) { ... } The binder is connected to the bean and correctly reads the bean values when the view is entered. Changing a field value correctly causes the binder to return hasChanges=true and isValid=true. No exception is thrown in the code and after binder.writeBean(), hasChanges returns false. Yet, the bean still contains the old values. These are pure textfields and string values, so it’s not a converting/datatype issue.

Using Vaadin 8.1.0.beta3/Spring-boot/JPA/Hibernate.

Anyone else experienced this?

Hi,

can you run the code in debugger and see what happens there? Is the binder connected to the correct Field? If you step into the writeBean method, what happens there?

Best regards,

Olli

Hi Olli,

The binder was connected alright. I found the issue for the problem. The entity was returning itself in the setter method and it is what caused the setting to fail.

The following setter doesn’t work:

public User setLastname(String lastname) { this.lastname = lastname; return this; } But this works:

   public void setLastname(String lastname) {
      this.lastname = lastname;
   }

It would be great if the automatic binding will work with beans that has a return value, but it’s not a huge issue.

Right, I’ve used that pattern myself occasionally. If you have the time, you could write a a feature request in the Framework GitHub: https://github.com/vaadin/framework/issues

-Olli