vaadin中将多选框的值映射到BeanItem<Bean>的bean中。
本来想把Java Bean绑定到vaadin的Form中,可是bean中有个类型List<String>的属性,用来保存用户有很多爱好。
不料在form commit后一直报错。一步步跟代码最后找到原因,只要将List<String>改成Collection<String>就没有问题了,也可以是HashSet.其实只要是任何HashSet的子类或者被HashSet实现的接口就行。
看ObjectProperty.java的代码:
if ((newValue == null) || (type.isAssignableFrom(newValue.getClass()))) { Object value = newValue; this.value = value; } else { try { Constructor constr = getType().getConstructor(new Class[] { String.class }); this.value = constr.newInstance(new Object[] { newValue.toString() }); } catch (Exception e) { throw new Property.ConversionException(e); } }