1

I'm currently trying to use a binder in Vaadin to access a nested property of an object. After googling a bit I found a reference example which sums up my problem quite well (Original post).:

Assume you have 2 beans:

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

You think you should be able to do smthing like this:

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

How ever this results in an exception. Following the discussion of Vaadins repository this issue was closed by something called NestedPropertyDefinitions (Potential solution referenced in the issue discussion which lead to closing the issue).

I was looking it up but merely found any information how to use it or how to easily access nested properties with the Vaadin binding system except for this one Documentation.

Can anyone explain to me how to use NestedPropertyDefinitions ?

LOLWTFasdasd asdad
  • 2,625
  • 5
  • 26
  • 39
  • IIRC, `binder.bind(new TextField(), "sub.name");` is just a short form for `binder.forField(new TextField()).bind("sub.name");`. Are you absolutely sure that one works and the other doesn't? – kscherrer Apr 04 '19 at 13:06
  • Thanks for your reply. The error was on my side! I updated my question. Would be great if Vaadin devs could add an nested example on this page: https://vaadin.com/docs/flow/binding-data/tutorial-flow-components-binder.html – LOLWTFasdasd asdad Apr 04 '19 at 13:30
  • 1
    I think this is mentioned 3 sub-menu points further down: [Binding Beans to Forms](https://vaadin.com/docs/v13/flow/binding-data/tutorial-flow-components-binder-beans.html). Well, not mentioned with words, but used in the first code sample. And yes `NestedPropertyDefinitions` is only used internally. When binding with a property-name string, it looks if that string has a `.` in it. if yes, it will automatically create and return a NestedPropertyDefinitions – kscherrer Apr 04 '19 at 13:34
  • Ah you're right. How could I not find this one? Thank's for your help and providing insights, much appreciated! – LOLWTFasdasd asdad Apr 04 '19 at 13:38

1 Answers1

0

I found out that this:

binder.forField(new TextField()).bind("sub.name")

works in Vaadin 12.0.7. It does for grids and binders as well. Apparently there is no need to use NestedPropertyDefinitions to achieve nested bindings. I had a bug on my backend side which caused an error that made me assume the binding did not work properly. So I still can't tell if there is another way of achieving this or what NestedPropertyDefinitionsdo but I'd assume that they are used by Vaadin internally.

According to Cashbees comment NestedPropertyDefinitions is only used internally and how to deal with nested properties is indirecetly referenced in this documentation.

LOLWTFasdasd asdad
  • 2,625
  • 5
  • 26
  • 39