Hello,
during development with the databinding framework I found a strange
behaviour of the JavaBeansObservable (M20070822-0800):
Suppose we run the following simple code:
ModelBean modelBean = new ModelBean();
ModelBean targetBean = new ModelBean();
IObservableList modelBeanObservableList =
BeansObservables.observeList(Realm.getDefault(), modelBean, "list",
String.class);
IObservableList targetBeanObservableList =
BeansObservables.observeList(Realm.getDefault(), targetBean, "list",
String.class);
DataBindingContext bindingContext = new DataBindingContext();
bindingContext.bindList(targetBeanObservableList, modelBeanObservableList,
null, null);
modelBean.add("Str 1");
modelBean.clear();
targetBean.add("Str 2");
for(Object o : modelBean.getList()){
System.out.println(o);
}
ModelBean has a simple array list containing strings and clear() resets the
list. Any other modification of the list can be imagined.
One would expect the console to output: "Str2". But surprisingly there is no
output at all - the model was not updated.
When I debugged the code of JavaBeansObservable I found out the place, where
the underlying writeableList is updated:
public void add(int index, Object element) {
...
wrappedList.add(index, element);
...
}
But this line throws an exception (UnsupportedOperationException?) as
wrappedList is not of type ArrayList but Arrays$ArrayList.
I question myself, what did I wrong?
Nice Greetings,
Masroor