I’m fairly new to Vaadin and I’m working on implementing a resource class. The class creates resources internal and external.
Here’s basically what I wrote.
VerticalLayout layout = new VeriticalLayout();
String fileLocation = "e:/home/application/media/logo.png"
Resource res = new FileResource(new File(fileLocation));
Image image = new Image(null, res);
layout.addComponent(image);
When I view this layout in the web browser, the image is broken. If I choose a file location that is in the container as follows, the link is STILL broken.
VerticalLayout layout = new VeriticalLayout();
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
FileResource resource = new FileResource(new File(basepath + "/WEB-INF/images/logo.png"));
Image image = new Image(null, res);
layout.addComponent(image);
Sadly, this last one is a rehash of what’s on
Vaadin’s website
which should of worked. In either case, if I look at the HTML code that is generated for the location of the image, I get something like this.
https://localhost/app/vaadinServlet/APP/connector/0/5/source/logo.png
Also, I have used FilenameUtils.separatorsToSystem to set the fileLocation to platform specific with same results.
I’m not sure if any of these last pieces of extra information help, but what am I doing wrong? Why am I getting a broken image?
I even tried to use StreamResource.
StreamSource imagesource = new MyStreamSource();
StreamResource resource = new StreamResource(imagesource, "myimage.png");
Image image = new Image(null, resource);
I implemented MyStreamResource to read the image using input/output streams, but there is no image. For the sake of argument, I placed log messages in the implemented getStream which MyStreamSource overrides and no output messages were produced. Why isn’t getStream being called?!?
Lastly, I should mention that ThemeResource does work. All other methods of Resource, so far, have not.
Any insight to these issues is greatly appreciated.