Issue:
In the current version, the download Anchor's href value is only set when created, but does not get updated when the PdfViewer::setSrc methods are called.
Fix:
Update anchor's href when setSrc methods are called.
Code to Test Issue/Fix:
@Route(value = "", layout = MainLayout.class)
public class ExampleView extends FlexLayout {
public BasicPdfViewerExample() {
setSizeFull();
PdfViewer pdfViewer = new PdfViewer();
pdfViewer.setSizeFull();
pdfViewer.setSrc("");
ComboBox<String> files = new ComboBox<>("Select PDF");
files.setItems("bitcoin.pdf", "example.pdf", "example-invoice.pdf");
files.addValueChangeListener(e -> {
String filename = e.getValue();
if (StringUtils.isEmpty(filename)) {
pdfViewer.setSrc("");
return;
}
try
{
byte[] contents = getClass().getResourceAsStream("/pdf/" + filename).readAllBytes();
pdfViewer.setSrc(new StreamResource(filename, () -> new ByteArrayInputStream(contents)));
} catch (Exception ex)
{
Notification.show("Failed to load file");
ex.printStackTrace();
}
});
add(files, pdfViewer);
setFlexGrow(1, pdfViewer);
}
}
Issue: In the current version, the download Anchor's href value is only set when created, but does not get updated when the PdfViewer::setSrc methods are called.
Fix: Update anchor's href when setSrc methods are called.
Code to Test Issue/Fix: