2015-01-27 75 views
0

我試圖修改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;  
      }  

請幫忙.. !!

回答

1

您使用setValue來設置表中顯示的值。並且在填充它們之前確保設置相應的容器屬性。

如果您只是想知道如何使用SQLContainer將地址簿演示綁定到MySQL數據庫,那麼您可以看看https://vaadin.com/tutorial/sql,它幾乎在內存容器離開您的地方繼續。

當然,如果你有其他一些綁定到你的數據JPA,in-memory beans等,你可能想看看適合你的需要。

+0

謝謝我會研究它 – 2015-01-28 02:56:24