Flow: Imprve Binder API for read-only properties

Created on 22 Jan 2019  路  3Comments  路  Source: vaadin/flow

Currently (Vaadin 12) Binder requires developer to pass null as "setter" when doing manual binding from properties to HasValue UI fields. For read only fields there could be overloaded methods with simpler signature or methods with different method names.

For example this:

TextField fullName = new TextField();
binder.forField(fullName).bind(Person::getFullName, null)

could become

TextField fullName = new TextField();
binder.forField(fullName).bind(Person::getFullName)

or

TextField fullName = new TextField();
binder.forField(fullName).bindReadOnly(Person::getFullName)
Help wanted binder enhancement

Most helpful comment

Out of those options, I'd strongly suggest a separate method name that clearly distinguishes the readonly case from the regular case. This would help avoid omitting the setter by mistake and would also make it slightly easier to understand what's going on just by reading the code. The suggested bindReadOnly seems like a good candidate for that name.

All 3 comments

Out of those options, I'd strongly suggest a separate method name that clearly distinguishes the readonly case from the regular case. This would help avoid omitting the setter by mistake and would also make it slightly easier to understand what's going on just by reading the code. The suggested bindReadOnly seems like a good candidate for that name.

And it would be very useful when bindReadOnly also supports readonly components like label.

And it would be very useful when bindReadOnly also supports readonly components like label.

I think this would make sense as I've seen this requested several times in our internal Slack.

Another related issue about whether or not the read only (or disabled or such) fields should be possible to ignore validation/required status #6682

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefanuebe picture stefanuebe  路  4Comments

pleku picture pleku  路  4Comments

rucko24 picture rucko24  路  3Comments

joheriks picture joheriks  路  4Comments

anezthes picture anezthes  路  4Comments