作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用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/
我最近看到了cloud_firestore: ^2.0.0更新带来了新的 withConverter 功能。 我想用它来检索我的模型并将其传递到 Firestore,但我不太确定如何使用现有代码执行此
我有约会与学生和老师的集合为reference与其他字段一起输入。 我想使用 CollectionReference.withConverter 获取约会列表.但是由于引用字段,我无法获取它们。 示例
使用Binder时如何防止显示文本“null” withConverter方法 TextField id = new TextField("Id"); TextField name =
我是一名优秀的程序员,十分优秀!