Form data bindings to private fields

Hi guys,

I noticed the changes in the way of creating forms in Vaadin 7 and think they are very positive.

There’s only one nice thing that was working great before and that I can’t seem to replicate anymore. I have a big set of JPA entities and need to create some generic forms for editing them.

I have been able to create the generic forms with FieldGroup and binding it with a BeanItem. The code I am using basically is:


        BeanItem<EntityInterface> entityBean = new BeanItem<EntityInterface>(entity); 
        fieldGroup.setItemDataSource(entityBean);

        for (Object property : fieldGroup.getUnboundPropertyIds()) {
            Field field = fieldGroup.buildAndBind(property);
            field.setWidth(100, Unit.PERCENTAGE);
            panel.addComponent(field);
        }

Before I was simply linking the form to the BeanItem. The result is almost identical, only that some of the methods in the JPA entities have private setters. When this happened with the old Form system, the fields binded to the private setters would display the content but would not be enabled for editing.

Any ideas on about how can I replicate this behaviour in Vaadin 7?

Thank you in advance!

Any ideas guys?

Could you tell me if this is bugged so I can go back to the old form system?

Haven’t tested this but the Property should be read only if it has no public setter method. You should therefore be able to do

and get the result you desire.

Thank you,

this does the trick in the UI. Efectively doing so detects that the field should not be written and shows it as disabled.

The bad thing is that when you commit changes Vaadin tries to write the field (even if you were not able to edit it) throwing a com.vaadin.data.Property$ReadOnlyException.

Are you sure this is not bugged?

Think it may be related to this ticket: http://dev.vaadin.com/ticket/9076

You are doing great BTW!

Yes, it’s a bug and #9076 should fix it

Perfect, thank you :slight_smile: