java - 如何在 Vaadin 上使用 withConverter 方法防止 Binder 中出现 “null” 文本

标签 java vaadin vaadin8

使用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);

结果是这样的:

enter image description here

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/

相关文章:

java - Spring不解析具有相同URL前缀的JSP和JSON

Java - Vaadin - 表未填充

java - 在 Vaadin 中设置 GridLayout 行高

postgresql - JPA/hibernate/PostgresDB 和 Vaadin 8 : SQL select query to get data from inherited tables and show in Vaadin grid

java - 如何在 vaadin 8 中导出 "filtered"网格?

java - 如何识别 SelectedTabChange Listener 中选定的选项卡?

java - Spring Boot jpa Multi-Tenancy 与动态数据源

java - EntityManagerFactory接口(interface)[interface javax.persistence.EntityManagerFactory]似乎与Spring的EntityManagerFactoryInfo mixin冲突

c# - Java SecretKey 并在 C# 中复制它的行为

java - Vaadin MySQL 获取