【问题标题】:How to populate table with specific values instead of pseudo-random?如何用特定值而不是伪随机填充表?
【发布时间】:2015-01-27 00:59:25
【问题描述】:

我正在尝试将 vaadin 地址簿应用程序修改为稍微不同的应用程序,只是更改了字段名称。但我不知道如何用特定值而不是 vaadin 教程示例中的伪随机填充它。 这是我的代码。

private static IndexedContainer createDummyDatasource() {    
    IndexedContainer ic = new IndexedContainer();    
    for (String p : fieldNames) {    
    ic.addContainerProperty(p, String.class, "");    
    }    
    String[] cnumber = { "1", "2", "3" };    
            String[] ctitle = { "a", "b", "c" };    
            String[] faculty = { "xxx" };    
            for (int i = 0; i < 3; i++) {    
            Object id = ic.addItem();    
            ic.getContainerProperty(id, CNUMBER).setValue(cnumber[(int) (cnumber.length * Math.random())]);    
            ic.getContainerProperty(id, CTITLE).setValue(ctitle[(int) (ctitle.length * Math.random())]);    
            ic.getContainerProperty(id, FACULTY).setValue(faculty[(int) (faculty.length * Math.random())]);    
            }    
            return ic;    
            }    

请帮忙..!!

【问题讨论】:

    标签: eclipse vaadin addressbook


    【解决方案1】:

    您使用 setValue 设置表中显示的值。并且还要确保在填充它们之前设置了相应的容器属性。

    如果您只想知道如何使用SQLContainer 将地址簿演示绑定到 MySQL 数据库,那么您可以查看https://vaadin.com/tutorial/sql,它几乎可以从内存容器离开您的位置继续。

    当然,如果您对数据 JPAin-memory beans 等有其他绑定,您可能需要查看适合您需要的那个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      相关资源
      最近更新 更多