0

i'm trying to modify the vaadin addressbook app to a little different one with just the field names changed. but i do not know how to populate it with specific value instead of the pseudo-random as done in the vaadin tutorial example. here is my code.

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;    
            }    

please help..!!

1 Answers1

1

You use the setValue to set the values shown in table. And also make sure the corresponding container property is set before populating them.

If you just want to know how to bind the address book demo to an MySQL database using SQLContainer, then you can have a look at https://vaadin.com/tutorial/sql which pretty much continues where the in-memory container left you.

Of course if you have some other binding to your data JPA, in-memory beans etc, you might want to have a look at the appropriate one for your needs.

Jonas Granvik
  • 935
  • 7
  • 13