Binded fields in FieldGroup not readonly when setting ItemDataSource

Hi,

I’m using Vaadin 7 Alpha 3. When setting fields to readonly it has no effect. Disabling doesn’t work, too.


FieldGroup fieldGroup = new BeanFieldGroup<User>(User.class);
[b]
fieldGroup.setItemDataSource(new BeanItem<User>(sessionUser));
[/b]

TextField pseudonymTextField = new TextField("Pseudonym");
[b]
pseudonymTextField.setReadOnly(true);
[/b]
fieldGroup.bind(pseudonymTextField, "pseudonym");
addComponent(pseudonymTextField);

The TextField is not readonly. When not setting the ItemDataSource then it works fine.
Is it a bug or what is the problem?

Greetings
Maik

FieldGroup has its own
ReadOnly
and
Enabled
properties. With these, you can set all fields managed by the FieldGroup to read-only or disable them. When you bind a field to an item property with FieldGroup, the bound field is configured according to the current values of
ReadOnly
and
Enabled
of FieldGroup which will override any settings the field had before binding. A simple solution to your problem would be to make your TextField read-only after binding it with FieldGroup, like so:


TextField pseudonymTextField = new TextField("Pseudonym");
fieldGroup.bind(pseudonymTextField, "pseudonym");
addComponent(pseudonymTextField);
pseudonymTextField.setReadOnly(true);

Edit: There’s been filed a bug regarding the behaviour of FieldGroups in such a scenario:
#9076

It looks like this was addressed for preconfigured “setReadOnly” fields, but not setEnabled()

Yes, same problem today, with Vaadin 7
(in setEnabled)

Idem