vaadin-component-factory / vcf-pdf-viewer-flow

Vaadin Addon for providing pdf viewing functionality
Apache License 2.0
8 stars 6 forks source link

Viewer works in one app but in the other only shows the download button #43

Closed FollowSteph closed 11 months ago

FollowSteph commented 11 months ago

The code is very basic and both apps have the exact same code (and all the same dependencies, versions, and so on in the pom files). They also point to the same example file (the one from the online demo for the component).

import com.vaadin.componentfactory.pdfviewer.PdfViewer;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.StreamResource;

@PageTitle("Main")
@Route(value = "testpdf")
public class TestView extends HorizontalLayout {

    public TestView() {
        Button button = new Button("test app");
        PdfViewer pdfViewer = new PdfViewer();

        add(button);
        add(pdfViewer);

        StreamResource streamResource = new StreamResource("example.pdf", () -> getClass().getResourceAsStream("/META-INF/resources/pdf/example.pdf"));
        pdfViewer.setSrc(streamResource);
    }
}

What's very weird is that in the test app that has absolutely nothing else (no other views, etc) it works perfectly. However in the main application it only shows the download button, not the viewer. What's even more odd is the download button works as expected in the main, the only thing that doesn't work is that the viewer itself is missing. Again it's just that the viewer is missing. They both have the same identical code, even the resource is located at the same location and so on. The only difference is the package name.

And everything is on the latest version of Vaadin, the component, etc. Java is on 20.0.1

Any suggestions would be appreciated.

FollowSteph commented 11 months ago

I finally figured it out luck. I'll close the comment but I'm commenting in case you want to know should you ever run into this issue again. It took me way too long to figure it out, and it was something silly in the end.

Essentially in application.properties file I had set vaadin.whitelisted-packages to be slash separated instead of comma separated. I'm not sure why, I think it was something historical. In any case the end result was that it failed to render the component outside of the download button. Changing it to comma's, even if there doesn't appear to be any relevance to this component, immediately fixed the issue. I'm not sure why but I'm just letting you know in case someone else encounters the issue.