I am using vaadin 14 to develop a web page. I have used @PreserveOnRefresh, so that my ui won't change upon refresh. I am able to achieve it, but am losing the images. On first attempt I am able to load the image, but after refresh the images are lost. I have created the image via StreamResource. Can anybody please help me with this usecase? The following is my code snippet:
@Route("home")
@PreserveOnRefresh
public class HomePage extends VerticalLayout {
public HomePage(HorizontalLayout base) {
Div logoContainer = new Div();
logoContainer.setSizeFull();
StreamResource streamResource = new StreamResource("logo", () -> {
File imgrsc = new File(filepath-to-my-image);
FileInputStream stream = null;
try {
stream = new FileInputStream(imgrsc);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
return stream;
});
Image image = new Image(streamResource, "");
logoContainer.add(image);
base.add(logoContainer);
}
}
I am expecting for my image to be loaded after refresh button/F5 is clicked