使用Binder
时如何防止显示文本“null”
withConverter
方法
TextField id = new TextField("Id");
TextField name = new TextField("Name");
Binder<Customer> b = new Binder<>();
b.forField(id)
.withConverter(Integer::valueOf, String::valueOf, "Invalid")
.bind(Customer::getId, Customer::setId);
b.forField(name)
.bind(Customer::getName, Customer::setName);
b.readBean(customer);
结果是这样的:
How do the conversion without losing the validation type?
最佳答案
最后,我找到了使用vaadin API的解决方案,感谢帮助@Shirkam
b.forField(id)
.withConverter(Integer::valueOf, String::valueOf, "Invalid")
.withNullRepresentation(0)
.withValidator(new IntegerRangeValidator("Value must be greater than 0 ", 1, null))
.bind(Customer::getId, Customer::setId);
b.forField(name)
.bind(Customer::getName, Customer::setName);
b.readBean(customer);
关于java - 如何在 Vaadin 上使用 withConverter 方法防止 Binder 中出现 “null” 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46472811/