BrowserFrame for HTML in string resource using StreamResource

I noted that in Vaadin 7.0.6, sometimes my BrowserFrame contents are blank. In my case, I have the HTML to render (in our case, it’s the HTML content used in an email that was sent out) via a StreamResource that I set as the BrowserFrame.source(). Often, the first time I use it, the content is rendered fine, but when I revisit, the HTML frame is often empty and not showing the content I provided via the StreamResource. In the DOM, it appears as an IFRAME with a link to the get the resource, but somehow that doesn’t always work.

The basic code is:


				final byte[] htmlData = EsfString.stringToBytes(html); // basically doing html.getBytes("UTF-8")
				StreamResource.StreamSource ss = new StreamResource.StreamSource() {
					private static final long serialVersionUID = 8337866232702077402L;

					InputStream is = new BufferedInputStream(new ByteArrayInputStream(htmlData));
					@Override
					public InputStream getStream() {
						return is;
					}
				};

				BrowserFrame emailFrame = new BrowserFrame();
				emailFrame.setWidth(100,Unit.PERCENTAGE);
				emailFrame.setHeight(98,Unit.PERCENTAGE);
				emailFrame.setSource(new StreamResource(ss,"email.html"));
				panelLayout.addComponent( emailFrame );

Is there something I need to release specially on detach or the like when I’m doing this? In debug, I can see that I am always providing the correct HTML string data, but somehow these dynamic resources are not being returned correctly via the IFRAME src link generated (when I click on the resource URL, it also shows empty in my browser).

When do such dynamic resource URL contents get released? Can I force their release when my window closes that contains my Panel with a BrowserFrame inside? Thanks!

I “fixed” this myself by switching to an ExternalResource link to a servlet that returns the content. This always seems to work, and I do it by storing the dynamic data into my http session attribute using a random name that I pass in the URL to my servlet. The servlet just retrieves it and writes it out. And in my view, when detach() is called, I then remove the attribute from the session.

It seems that Vaadin could have done something similar with its dynamic URLs it generates for stream resources, by adding them as created and then removing (and closing if necessary) them as the containing widget is detached.

I have the same problem - in the meantime with vaadin 8.2

Does sombody know a solution without using ExternalResource ?