In my application I am making good use of Vaadin’s Binder concept (which I find superb and extremely elegant and powerful, btw).
But - since my application keeps growing - the desire came up to make these Binders nestable. I.e. could one form with a binder contain another (sub-)form that has its own binder? And could the outer binder’s status methods (isValid() / hasChanges() / …) as well as a binder’s statusListener-events also cover such “contained” sub-binders?
I guess that’s not readily available but is there maybe a suggested/preferred pattern to combine those? Or a good example?
I’ll try to explain what I mean by “nestable bindings” or “sub-bindings”:
I have an entity type, say, A
with fields a,b,c
:
class A {
int a;
boolean b;
String c;
}
For that entity I have defined me a Form_A
with a Binder<A>
that handles the updating and validation of the form and a corresponding bean.
I have another entity, here called B
class B {
String d;
boolean e;
}
which is also used in other contexts and for which I already defined an other FormB
and Binder<B>
.
Now I want to extend A
with an additional field of class B
like so:
class A {
int a;
boolean b;
String c;
B x;
}
I know that I could extend A
’s form with suited fields and connect these with A
’s Binder using a nested property by referring to that fields via a dot notation, here e.g. as x.d
and x.e
. I find that approach not so scalable - esp. when considering real-life (i.e. bigger and much more complex) forms.
Rather I envision something where I could define a field and a binder as “sub-forms” by hooking these into the parent binders by specifying something like
FormA() {
... // defining components for fields a, b and c
FormB formB = new FormB(); // FormB defines a Form for an entity `B` and a `Binder<B>`.
add(formB); // add the form for B as a sub-component (i.e. a part) of the form for A
binderA.forField(x).useSubBinder(formB.getBinder()); // define `formB`s binder to handle field `x` and hook it into the binder for `FormA`
...
}
...
foo = binderA.isValid(); // this should also contain whether all fields of `x` are valid
...
bar = binderA.hasChanges(); // this should also contain whether any fields of `x` have changed.
Hope, I could make myself clear…