Local htm file embedded in vaadin

I am new to vaadin and somehow managed to run the application. Now I have a help.htm html file containing tips on using the application. I put the help.htm file in the WEB directory of my project in order to have access to it in the vaadin context. I tried to access it this way:

String str = "file:/" + "/" + application.getContext().getBaseDirectory() + "/help.htm"; URL url = new URL(str); Embedded browser = new Embedded("Help", new ExternalResource(url)); browser.setType(Embedded.TYPE_BROWSER); tabsheet.addComponent(browser); 

I tried to debug, copy and paste the contents of the str variable into my web browser, I can access the file and the browser displays it correctly. I also tried with FileResource and ClassResource. Also, when I replace the string with http://www.somewebpage.com/, it works, but not with the code above. How to achieve this?

+7
source share
1 answer

Vaadin has 5 different resources, depending on the circumstances: ExternalResource, ThemeResource, FileResource, ClassResource and StreamResource. If you want the file to be associated with your application, you can:

  • use ExternalResource (referring to your resource as http : // host: port / etc / etc) or

  • use ThemeResource (referring to your resource through its relative path to the WebContent / VAADIN / themes / yourtheme directory, where icons and styles are usually placed)

I would go with the second approach because it frees you from searching for the context url.

More about resources here and here .

+7
source

Source: https://habr.com/ru/post/903309/


All Articles