How to load static html content into a Window?

I’d like to show a popup and load some static text or moreover html content from a file.

It works with an image, but using a *.txt file the window just remains blank. Why?

Embedded file = new Embedded("Logo", new ThemeResource("img/logo.png"));
// file = new Embedded("Settings", new ThemeResource("layout/example.txt")); //does not work

Embedded only supports certain types of content.

To display HTML text from the same server, the easiest way is usually to use a Label - for HTML content use the (X)HTML content mode.

OK I see I can use

Label label = new Label("<b>my bold text</b>");

But how can I get the ThemeResource (*.html or *.txt) into a label?

There probably isn’t really a reason for the files to be in the theme in this case but could be loaded in some other way.

See also
this thread
. There isn’t a fully generic way to get a theme resource on the server side (in some deployment scenarios, the actual content could even come from a separate server that is not accessible from the main server), but for many applications a workaround like the one presented there works. In that case, though, if the name of the file that is shown is based on user input of any kind, one should be very, very, very careful not to expose other resources that are on the classpath to a malicious user crafting his own queries.

Using a BrowserFrame (Vaadin 7.0+) component might be an alternative for showing HTML and perhaps also other file types coming from the theme or other resources.

OK so probably using a ClassLoader to fetch the *.html file, convert it toString with Apache IO Utils and wrap it inside a Label with ContentMode.HTML is the best way to include custom html-formatted filecontent as a piece on a page. Or could I do better?

Nope, that’s standard approach to display arbitrary HTML content in a Vaadin application; one “caveat” - any external files (e.g. css, images) referred to in the HTML file will not be loaded.

If you have a plain text file, use ContentMode.TEXT