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)
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
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
bindReadOnlyseems like a good candidate for that name.