Can't change property in BeanItemContainer

Hi guys,

I’m using the Vaadin Calendar with a BeanItemContainer as container.
I can add my events and they aare well displaying in the Calendar but when I’m trying to drag an event, I got this error :

Caused by: com.vaadin.data.Property$ReadOnlyException
    at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:658)
    at com.vaadin.ui.components.calendar.ContainerEventProvider.eventMove(ContainerEventProvider.java:492)
    at com.vaadin.ui.Calendar.fireEventMove(Calendar.java:935)
    at com.vaadin.ui.Calendar$CalendarServerRpcImpl.eventMove(Calendar.java:1688)
    ... 37 more

Which corresponds to the following line in the ContainerEventProvider class :

item.getItemProperty(startDateProperty).setValue(event.getNewStart());

I tried to manually set this property to readOnly = true and to change manually the value, but I’m getting the same error.
I also can display the value if I’m calling the getValue() method.

I really can’t figure out what’s wrong, here’s my code :

@UIScoped // Using the cdi-MVP addon
public class CalendarComponent extends ViewComponent {

    private BeanItemContainer<CalendarEvent> container;
    @Inject
    private CustomCalendar calendar; //Just an extend of the calendar, I only overrided the getDayNamesShort() method

    public void init() {
        setSizeFull();
        setCompositionRoot(calendar);
        container = new BeanItemContainer<CalendarEvent>(CalendarEvent.class);
        calendar.setContainerDataSource(container, "caption", "description", "start", "end", "styleName");
    }

// called after a fireEvent(), it works fine because it displays the events on the calendar
    public void setEventList(final List<CalendarEvent> listeEvents) {
        container.removeAllItems();
        container.addAll(listeEvents);
        container.sort(new Object[]{"start"}, new boolean[]
{true});
    }

Any ideas ?

Thanks,

Cédric

I “solved” the problem using BeanContainer instead of BeanItemContainer, and everything is working.

This guy faced the same problem as me :

http://johnsjavapda.blogspot.fr/2013/06/vaadin-beanitemcontainer-vs.html

He explained why it didn’t work with the BeanItemContainer, it has something to do with hashCode() method, but I don’t understand the point.

It is hard for me to see how using BeanContainer instead of BeanItemContainer solves the issue you mentioned above, although it can solve other potential problems. I suppose you also made other changes than just changing the container type.

The ReadOnlyException was thrown because your BeanItemContainer was initialized with the interface CalendarEvent, which only contains the getters and no setters. Thus, the properties are detected as read-only, as properties are scanned from the given class rather than the actual classes of the event instances.