0

I want to display a static html file in a vaadin view. I use the com.vaadin.server.FileResource class to this like under:

String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
FileResource resource = new FileResource(new File(basepath + "/WEB-INF/my_file.html"));

But I dont know what can I use this.?

Gregory01
  • 97
  • 10

2 Answers2

1

You can use the Label component for this. Just set it to HTML content mode and read the content of the HTML file and set it as the label text.

See also here

Community
  • 1
  • 1
André Schild
  • 4,592
  • 5
  • 28
  • 42
  • Thank you very much for your answer. I know this trick, but what do you think shall I use some labels for some paragraph? Or I can use one label to this. Which is better? (I came from this for I use com.vaadin.server.FileResource...) – Gregory01 Jun 26 '15 at 11:54
  • I don't understand your question... what paragraphs? Having less components in the DOM tree is always a good idea, so put them all in one label if possible – André Schild Jun 26 '15 at 11:56
  • When I want to simulate this example (http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_name), I face with a strange. The browser try to navigate me to "C4" view, but I want to navigate within the page. How can I solved this? – Gregory01 Jun 26 '15 at 12:06
  • 1
    Also note that it is always good idea to sanitize your html (with tools like OWASP HTML Sanitizer) when source html comes from untrusted source. Otherwise you are vulnerable to attacks such as Cross Site Scripting. – Vojtech Ruzicka Jun 26 '15 at 14:49
  • When you look at the generated html on the page, does it still have the #C4 in the href? – André Schild Jun 26 '15 at 15:19
0

You can put your static html file into your theme directory and use the ThemeResource class to load the content and the BrowserFrame to render one:

ThemeResource html = new ThemeResource("static.html");
BrowserFrame frame = new BrowserFrame("Static", html);

http://files.rsdn.ru/12237/vaadin_static.PNG

AnatolyS
  • 4,249
  • 18
  • 28