Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[riena-dev] 264325 - NoSuchMethodException and POJOs

Just a quick heads-up:

The 3.5 databinding is more strict and will throw
NoSuchMethodException when using BeanObservables with a POJO (i.e. a
class that does not accept property change listeners). The exception
usually does not cause any harm, however it is written to the log. The
solution is very easy. Use PojoObservables instead:

Exception:

!MESSAGE Could not attach listener to
org.eclipse.riena.example.client.controllers.SharedViewDemoSubModuleController$TxtBean@1a1a1c6
!STACK 0
java.lang.NoSuchMethodException:
org.eclipse.riena.example.client.controllers.SharedViewDemoSubModuleController$TxtBean.addPropertyChangeListener(java.beans.PropertyChangeListener)
	at java.lang.Class.getMethod(Class.java:1605)
	at org.eclipse.core.internal.databinding.beans.BeanPropertyListenerSupport.processListener(BeanPropertyListenerSupport.java:96)
[...]
	
Problem:

TxtBean bean = new TxtBean();
// TxtBean is actually NOT a bean - its a POJO.
// bindToModel uses BeansObservables.observeValue(bean, "txt")
internaly because it expects a bean
// => exception
labelFacade.bindToModel(bean, "txt");

Solution:

// use this variant of bindToModel together with PojoObservables:
labelFacade.bindToModel(PojoObservables.observeValue(bean, "txt"))

Hope this helps,
Elias.

PS: No need to do anything in the Examples. I'm taking care of this...


Back to the top