刚刚检查了默认转换器:它们不处理空/空,您必须实现一个可以做到的并将其设置为绑定。类似的,要查看区别,取消注释转换器设置:
@SuppressWarnings({ "rawtypes", "unchecked" })
private void bind() {
BindingGroup context = new BindingGroup();
AutoBinding firstBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE,
// this is some int property
this, BeanProperty.create("attempts"),
fields[0], BeanProperty.create("text"));
context.addBinding(firstBinding);
// firstBinding.setConverter(INT_TO_STRING_CONVERTER);
context.bind();
}
static final Converter<Integer, String> INT_TO_STRING_CONVERTER = new Converter<Integer, String>() {
@Override
public String convertForward(Integer value) {
return Integer.toString(value);
}
@Override
public Integer convertReverse(String value) {
if (value == null || value.trim().length() == 0) return 0;
return Integer.parseInt((String) value);
}
};