Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin 8 nested properties
Binding to a nested property seems only to work with lambda expressions, not with property names (String) or method reference.
My Problem is that the nested property can be NULL. In this case, the lambda expressions throw a null pointer exception.
What is the Vaadin way to handle this problem?
Hi Karl,
Could you please post some code sample so it would be easier to figure out what is happening?
For a nested property, you could do something like:
public class Address {
private String street;
...
}
public class Person {
private String name;
private Address address;
...
}
// binding to street
Binder<Person> binder = new Binder<>();
TextField streetField = new TextField();
binder.forField(streetField).bind(
person -> {
if (person.getAddress() != null) {
return person.getAddress().getStreet();
}
return ""; //if address is null, return empty string
},
(person, street) -> {
if (person.getAddress() != null) {
person.getAddress().setStreet(street);
} else {
// i.e. create a new address object
Address address = new Address();
address.setStreet(street);
person.setAddress(address)
}
});
( disclaimer: I haven't tested this code in an IDE, so there might be some mistakes :) )
Hope this helps, Goran