I got a little bit further (but maybe in the wrong direction?)
I added a @Configuration and in there a resourceHandler
In the view I added an iFrame inside a formLayout…
And then I tried this coding, but I get an error: stream closed
when I try to set the iframe source.
Any tip would be great.
public void onShowPDFClick(final ClickEvent<JmixButton> event) {
String fileName = "0aatest.pdf";
String fileNamePath = "objectplan/0aatest.pdf";
try {
File file = ResourceUtils.getFile(fileNamePath);
System.out.println(file.exists());
StreamResource resource = new StreamResource(fileName, () -> new BufferedInputStream(getClass().getClassLoader().getResourceAsStream(fileNamePath)));
StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
System.out.println(registration.getResourceUri().toString());
iframeID.setSrc(registration.getResourceUri().toString());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
the system.out:
true
VAADIN/dynamic/resource/1/e9e6882d-70ba-40f4-bcb9-1e304ee0c95d/0aatest.pdf
2023-09-10T22:24:16.252+02:00 ERROR 47960 — [nio-8080-exec-9] i.j.f.exception.UiExceptionHandlers : There is no io.jmix.flowui.exception.UiExceptionHandler can handle the exception
java.io.IOException: Stream closed
at java.base/java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:157) ~[na:na]
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:244) ~[na:na]
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:284) ~[na:na]
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:343) ~[na:na]…