Can BrowserFrame be given as a source string?

I’m currently using Vaadin 8. There is a BrowserFrame in my page and I want to give BrowserFrame an HTML string instead of a file as an argument. Is something like this possible?

String html = "<html>.....";
BrowserFrame bf = new Browser(null, html);

Thanks a lot.

You have two alternatives.

  1. If your html content is simple fragment of html, then BrowserFrame is a wrong component to use. You can use Label instead and set its content mode to be html.

  2. If your html content is a complex html structure (i.e. whole page), then BrowserFrame is correct. You can convert the String to accepted Resource type by using StreamResource. Something like:

	final StreamResource stream = new StreamResource(
			new StreamResource.StreamSource() {
				public InputStream getStream() {
					return new ByteArrayInputStream(("<html>...").getBytes());
			}, filename, this);

Thanks for your help. It worked.