Java Data Binding and Custom Converter -
i'm attempting bind atomicboolean "enabled" property of jcheckbox. since atomicboolean not replacement boolean i'm using custom converter. however, converter shown below results in classcastexception. why?
org.jdesktop.beansbinding.binding binding = org.jdesktop.beansbinding.bindings.createautobinding(org.jdesktop.beansbinding.autobinding.updatestrategy.read, isidle, org.jdesktop.beansbinding.objectproperty.create(), cornercb, org.jdesktop.beansbinding.beanproperty.create("enabled")); binding.setconverter(new converter<atomicboolean, boolean>() { @override public boolean convertforward(atomicboolean value) { boolean b = value.get(); return b; } @override public atomicboolean convertreverse(boolean value) { return new atomicboolean(value); } });
resulting exception
java.lang.classcastexception @ java.lang.class.cast(class.java:2990) @ org.jdesktop.beansbinding.binding.convertforward(binding.java:1312) @ org.jdesktop.beansbinding.binding.getsourcevaluefortarget(binding.java:844) @ org.jdesktop.beansbinding.binding.refreshunmanaged(binding.java:1222) @ org.jdesktop.beansbinding.binding.refresh(binding.java:1207) @ org.jdesktop.beansbinding.binding.refreshandnotify(binding.java:1143) @ org.jdesktop.beansbinding.autobinding.bindimpl(autobinding.java:197) @ org.jdesktop.beansbinding.binding.bindunmanaged(binding.java:959) @ org.jdesktop.beansbinding.binding.bind(binding.java:944) @ org.jdesktop.beansbinding.bindinggroup.bind(bindinggroup.java:143)
that exception isn't coming code. it's happening here:
private final tv convertforward(sv value) { if (converter == null) { class<?> targettype = noprimitivetype(targetproperty.getwritetype(targetobject)); return (tv)targettype.cast(converter.defaultconvert(value, targettype)); } return converter.convertforward(value); }
there couple of different maven artifacts have class in call class.cast() on line 1312. doesn't matter you're using. you'll need debugging. put breakpoint on line, , can trace call , see values being passed down , why exception happening. seems converter isn't being used reason, problem. it's trying cast atomicboolean boolean.
Comments
Post a Comment