Framework: Binder does not support sub properties

Created on 30 Jan 2017  路  6Comments  路  Source: vaadin/framework

If you have two beans:

public class Bean {
private SubBean sub;
// + getter setter
}
public class SubBean {
private String name;
// + getter setter



md5-fc7e22b3aa5d903214c535ff6ca20c65



Binder<Bean> binder = new Binder<>(Bean.class);
binder.bind(new TextField(), "sub.name");



md5-7a12d4cef0b93783ecb526a0928211b5



        binder.bind(new TextField(), bean -> {
            if (bean.getSub() == null) {
                return "";
            } else {
                return bean.getSub().getName();
            }
        }, (bean, value) -> {
            if (bean.getSub() == null) {
                bean.setSub(new SubBean());
            }
            bean.getSub().setName(value);
        });
candidate

Most helpful comment

Is this issue solved? I am getting the same error. And another question - does this work with subproperties that are collections, etc., lists?

All 6 comments

upgraded to vaadin 8.1.0

found two issues with nested properties and Grid:

1) works fine if nested property is not null - if nested property is null a null pointer is thrown

2) example: new Grid(Person.class);
nested property: address.street --> sets beanPropertySet with propertyId street and caches it --> BeanPropertySet line 309.
Second time the screen gets opened: Could not resolve property name street from Property set for bean Person

Thats due to the fact that the id was changed to street after first initialization (should be address.street)- so wrong caching of beanpropertyset is the problem.
Maybe separate caching for nested properties???

Is this issue solved? I am getting the same error. And another question - does this work with subproperties that are collections, etc., lists?

Just use the Method Referrences.

I got Error with
.bind(WerbungProperties.standzeitEnde.name());
but it works fine with
.bind(Werbung::getStandzeitBeginn, Werbung::setStandzeitBeginn);

I'm on 8.1.5 and it looks like it still doesn't handle nulls without exception. Is there an issue to address this?
It would be great to be able to do something like this

        client = new TextField("Client");
        client.setReadOnly(true);
        binder.forField(client).withNullRepresentation("").bind("timeMast.timemast_client.clientName");
        comps.add(client);

I do also seem to have a caching issue.

grid.addColumn("address.city")
When opening the view twice this would result in:
Caused by: java.lang.IllegalArgumentException: Could not resolve property name city from Property set for bean <<MyObject>> at com.vaadin.ui.Grid.lambda$addColumn$0(Grid.java:2535) ~[vaadin-server-8.1.6.jar:8.1.6] at java.util.Optional.orElseThrow(Optional.java:290) ~[na:1.8.0_131] at com.vaadin.ui.Grid.addColumn(Grid.java:2535) ~[vaadin-server-8.1.6.jar:8.1.6] at com.vaadin.ui.Grid.addColumn(Grid.java:2505) ~[vaadin-server-8.1.6.jar:8.1.6] at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:1.8.0_131] at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_131] at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1620) ~[na:1.8.0_131] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_131] at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_131] at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:1.8.0_131] at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:1.8.0_131] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_131] at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[na:1.8.0_131] at com.vaadin.ui.Grid.<init>(Grid.java:2368) ~[vaadin-server-8.1.6.jar:8.1.6] at com.vaadin.ui.Grid.<init>(Grid.java:2278) ~[vaadin-server-8.1.6.jar:8.1.6] at com.vaadin.ui.Grid.<init>(Grid.java:2259) ~[vaadin-server-8.1.6.jar:8.1.6] at lessoria.ui.rental_property.RentalPropertyView.<init>(RentalPropertyView.java:71) ~[bin/:na] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_131] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_131] at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE] ... 107 common frames omitted

For now it would also work with: grid.addColumn(object -> object.getAddress().getCity())

Hey, what was the result of this discussion? Do I need to use NestedPropertyDefinitions ? If yes is there a documentation how to do so?

Was this page helpful?
0 / 5 - 0 ratings