I have a image located at a saved position, what I recall from the DB. I want to show this image on my page.
[code]
File imageSrc = new File(questionProposalDTO.getPictureLocation());
if (!imageSrc.exists()) {
System.out.println("Input image at "
+ questionProposalDTO.getPictureLocation()
+ " does not exist.");
}
// Image as a file resource
FileResource resource = new FileResource(new File(
questionProposalDTO.getPictureLocation()));
// Show the image in the application
img = new Image("Image from file", resource);
img.requestRepaint();
[/code]The image isn’t shown! What am I doing wrong?
How is it not shown? Is the Image component shown in the UI otherwise OK? (I mean the caption, etc.) Is there a HTTP error when requesting the image content? (You can see that with Firebug or other web inspector.) Is there any error in the server log?
Note that there could be situations why a file could not be read even if it exists, such as if the server does not have permissions to read it.
I created the screen with the VaadIn designer . the image is located at my hardrive (location = ok) and it’s readable (common jpg). The image on the vaadin screen isn’t showing anything (nothing). I didn’t notice it but the caption is also not shown! I stated it in the Visual Designer but I don’t see it! The requestRepaint whas a final attempt to get something (allready removed).
If you use Designer, it the components are created when the design is read, but you are creating the Image component in your code yourself. I could guess that after doing so, you do not add it to the layout, hence it is not shown.
You should not again create components already created by Designer, but just modify them. In this case, you’d probably want to call img.setResource() instead of creating it and giving the resource in the constructor.
img.setSource(resource);
did the trick! I didn’t see setResource so i tried it as above. But it’s img.setSource(resource); thx to point me in the right direction!