Step by step - Vaadin 7.3.6 Document Manager application not working? It go

Good evening!

Trying to recreate the Vaadin Step by step Document Manager application (YouTube tutorial) but it seems to not work on Vaadin 7.3.6.

Here is the code:

@SuppressWarnings("serial")

@Theme("documentmanager")

public class DocUI extends UI {




FilesystemContainer fc = new FilesystemContainer(new File("/tmp"));

ComboBox docCb = new ComboBox("Documents", fc);

    

@WebServlet(value = "/*", asyncSupported = true)

@VaadinServletConfiguration(productionMode = false, ui = DocUI.class)

public static class Servlet extends VaadinServlet {

    }




@Override

protected void init(VaadinRequest request) {

        setContent(docCb);

    }




}

I would like it to show me a combobox with files inside the /tmp directory on my filesystem, but instead
when I run the application it get stuck and after it hangs for a long interval of time, I get a 500 Internal server error:

HTTP Status 500 - com.vaadin.server.ServiceException: java.lang.OutOfMemoryError: Java heap space

How can I resolve?

Hard to say, but I would start by pointing to some other folder where you only have files you know. Your temp folder could potentially have several gigs of files, so reading them might cause the heap space exhaustion.

The YouTube tutorial has been written for Vaadin 6.
Also, you may like to specify the entire/absolute path of the folder instead of just “/tmp”:

FilesystemContainer fc = new FilesystemContainer(new File("/tmp"));

@Marcus, thank you for pointing that out. So it’s possible that when I a directory is too big (i.e. contains several big files), the application stucks? Cause if I try to load another directory it works.

@Vikrant, the YouTube tutorial I followed was written in Vaadin 7 (7.0.0), anyway I have changed the path as you say to point to another dir with less files, and it works.

But how should I handle this 500 exception? Could you advise me a method to load even a big amount of big data using such approach with Vaadin, please?

The FileSystemContainer does not do any kind of lazy loading from the data source, just reads everything into memory. That’s why opening a big directory leads to the results you saw.

I haven’t really seen FileSystemContainer ever being used in a real life application, as data is usually stored in a database. If you have large amounts of data, you’ll need to defer loading until it’s needed. In Vaadin, this is accomplished by using a lazy loading container. There are some built in alternatives you can use like SQLContainer and JPAContainer. If you need something more generic, you might want to take a look at LazyQueryContainer. If you are just dealing with smaller data sets, a BeanItemContainer/IndexedContainer will probably be the easier alternative.

@Marcus, thank you very much!