So I am just opening a pdf file in a new tab.
private void help() {
try {
File file = new File(AppHelper.getJndiProperty("help.file"));
ByteArrayInputStream bais = new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
StreamResource resource = new StreamResource("help.pdf", () -> bais);
final StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry()
.registerResource(resource);
UI.getCurrent().getPage().open(registration.getResourceUri().toString());
} catch (Exception e) {
logger.error("USER: {} -> help -> FAILED: {}",user.userName,e.getMessage());
ErrorNotification errorNotification = new ErrorNotification("CONTACT SUPPORT - Open Help File Failed: " + e.getMessage());
errorNotification.open();
}
}
The javadoc for registerResource states:
Registers a stream resource in the session and returns registration handler.
You can get resource URI to use it in the application (e.g. set an attribute value or property value) via the registration handler. The registration handler should be used to unregister resource when it's not needed anymore. Note that it is the developer's responsibility to unregister resources. Otherwise resources won't be garbage collected until the session expires which causes memory leak.
Parameters:
resource stream resource to register
Returns:
registration handler
So any suggestions on how to properly unregister resource?