Has anyone been able to duplicate this type of functionality from the Vaadin 8 framework which was done similar to this code example:
private Label htmldoc = new Label(“”, ContentMode.HTML);
// read the document then set the contents as string
htmldoc.setValue(string value);
If you have a full HTML document (starting with <!DOCTYPE HTML><html>...
or similar), I’d recommend using an IFrame
component to embed the document. So
IFrame iFrame = new IFrame("hello-world.html");
Where to put your hello-world.html
depends on your project type (war
or jar
), see the “static files” reference here: https://vaadin.com/docs/v14/flow/importing-dependencies/tutorial-ways-of-importing.html#resource-cheat-sheet
If you have a shorter snippet (not a full document), you can use a Html
component. Note that Html
requires a single wrapping root element, so "<span>Hello <b>world</b></span>"
is ok while "Hello <b>world</b>"
is not. You can also use e.g. a Span
component and set the innerHtml
property through the Element API: span.getElement().setProperty("innerHTML", "Hello <b>World</b>");
Thanks Olli for the quick response! Using the IFrame worked for me. And thanks to the whole Vaadin team for a great framework.
Just a second note on my use case. I was trying to duplicate an example that was done a while ago in one of the Vaadin training courses. It created a file browser application which gave a list of directories and files on the left side column. And when a file was selected the file would show on the right side column. In this case my files are either text or html documents. Thanks again, Winston