Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Read objects from Folder
guys need help in reading objects from file.. here's my code.
// set a style name, so we can style rows and cells
table.setStyleName("iso3166");
// size
table.setWidth("100%");
table.setHeight("170px");
// selectable
table.setSelectable(true);
table.setMultiSelect(true);
table.setImmediate(true); // react at once when something is selected
// set column headers
table.addContainerProperty("Name", String.class, null);
//table.addContainerProperty("Size", String.class, null);
//table.addContainerProperty("Last Modified", String.class, null);
File directory = new File("C:/Users/Jet/Documents/error/uploads");
File fileList[] = directory.listFiles();
for(int i = 0; i < fileList.length; i++){
table.addItem( fileList[i].getName() );
System.out.println(fileList[i].getName());
}
addComponent(table);
the main problem is, I cant load the objects in my table. viewing output using System.out.print seems to work well w/ the objects, the only problem is loading them into the table.
Hi,
Table#addItem creates an item, but does not set any properties on it. Those properties displayed as the contents of the column..
I think you'll want to do something like the following :
for(int i = 0; i < fileList.length; i++){
Item item = table.addItem( fileList.getName() );
item.getProperty("Name").setValue(fileList.getName());
System.out.println(fileList.getName());
}
Cheers,
Charles.
Table.addItem(Object) takes an id of the item you are adding. Just adding items to table with addItem doesn't show anything in the table, because the container properties don't have value. Do e.g. like this
Object id = table.addItem();
table.getContainerProperty(id, "Name").setValue(fileList[i].getName());
Btw. there's also a com.vaadin.data.util.FilesystemContainer you could use and put it as a container data source for the table.