Excuse me, but i cant understand: why component doesn't work. Using Vaadin

Excuse me, but i cant understand: why component doesn’t work. Using Vaadin 14.2.3.


InputStream is, String fileName;

MemoryBuffer buffer = new MemoryBuffer();
upload = new Upload(buffer);
upload.addSucceededListener(event → {

		is = buffer.getInputStream();
		fileName = buffer.getFileName();

}
Then

sm.addItem(“Открыть документ”, e → {

StreamResource streamResource = new StreamResource(fileName, () -> is);
streamResource.setContentType("application/pdf");
streamResource.setCacheTime(0);
	
PdfBrowserViewer viewer = new PdfBrowserViewer(streamResource);
viewer.setHeight("100%");
add(viewer)

});

Result in attachment.

Maybe you need to call setHeightFull() on the layout?

I have the same problem.

Vaadin 14.3.4,
plugin 3.0.1

InputStreamFactory just isn’t called
18431026.png

Did you try setting a height for the parent layout?

Yes of course:

streamResource 
= new StreamResource(customFile.getPdfFileName(), () -> convertService.getConvertedToPdfInputStream(customFile));

pdfBrowserViewer = new PdfBrowserViewer(streamResource);
pdfBrowserViewer.setHeight("100%");
pdfBrowserViewer.setWidth("100%");
panel.setHeightFull();
panel.add(pdfBrowserViewer);

The method getConvertedToPdfInputStream() method is not called.

With version 1.0.0-alpha/1.0.0-alpha1 works fine

Ah sorry, I think the problem in your app is different to the one in the first question of this thread.

Are you able to provide the full source code?

The complete code is quite large. You are right, I will do a small test and send it with the result

Code:

public class CustomFileDemo extends VerticalLayout {
    public static final String route = "customFileUploadOnDemand";

    public CustomFileDemo() {

        log.info("CustomFileDemo - start");

        this.setSizeFull();
        StreamResource streamResource = new StreamResource("AnyFile.pdf",
            this::getInputStream);
        PdfBrowserViewer pdfBrowserViewer = new PdfBrowserViewer(streamResource);
        pdfBrowserViewer.setHeight("100%");

        VerticalLayout previewPanel = new VerticalLayout();
        previewPanel.setHeightFull();
        previewPanel.setWidthFull();
        previewPanel.add(new Label("Begin"), pdfBrowserViewer, new Label("End"));

        this.add(previewPanel);
        log.info("CustomFileDemo - initialized");
    }

    InputStream getInputStream() {
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream("/Users/pathToPdf/Work/IntelliJ_WS/workbaskets/src/main/resources/111.pdf");
        } catch (FileNotFoundException e) {
            log.info("File not found");
            e.printStackTrace();
        }
        log.info("File is here");
        return inputStream;
    }
}

It works nice with 1.0.0-alpha1 or 1.0.0-alpha.
In log:

10:31:02 [https-jsse-nio-9443-exec-2]
 INFO  d.x.w.filesCache.CustomFileDemo - CustomFileDemo - start
10:31:02 [https-jsse-nio-9443-exec-2]
 INFO  d.x.w.filesCache.CustomFileDemo - CustomFileDemo - initialized
10:31:02 [https-jsse-nio-9443-exec-2]
 INFO  d.x.w.commonUI.WorkbasketApp - WorkbasketApp. showRouterLayoutContent. contentLength: 0
10:31:02 [https-jsse-nio-9443-exec-2]
 INFO  d.x.w.commonUI.WorkbasketApp - WorkbasketApp. New content:  
10:31:02 [https-jsse-nio-9443-exec-2]
 WARN  c.v.f.s.c.r.AbstractRpcInvocationHandler - Got an RPC for non-existent node: 11
10:31:02 [https-jsse-nio-9443-exec-10]
 INFO  d.x.w.filesCache.CustomFileDemo - File is here

but with 3.0.1 looks like that:

10:41:27 [https-jsse-nio-9443-exec-8]
 INFO  d.x.w.filesCache.CustomFileDemo - CustomFileDemo - start
10:41:27 [https-jsse-nio-9443-exec-8]
 INFO  d.x.w.filesCache.CustomFileDemo - CustomFileDemo - initialized
10:41:27 [https-jsse-nio-9443-exec-8]
 INFO  d.x.w.commonUI.WorkbasketApp - WorkbasketApp. showRouterLayoutContent. contentLength: 0
10:41:27 [https-jsse-nio-9443-exec-8]
 INFO  d.x.w.commonUI.WorkbasketApp - WorkbasketApp. New content:  
10:41:27 [https-jsse-nio-9443-exec-8]
 WARN  c.v.f.s.c.r.AbstractRpcInvocationHandler - Got an RPC for non-existent node: 11

18435222.png

Thanks for the code. Have you tried with getClass().getResourceAsStream("/report.pdf")? The file should be located in the resources directory. The getInputStream method is actually called, so I wasn’t able to reproduce the issue.

I guess the problem is in the build tool - I am using gradle: