Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local htm file embedded in vaadin

Tags:

html

embed

vaadin

I'm new to vaadin, and I managed somehow to get an app up and running. Now I have an help.htm html file containing tips about how to use the app. I've put the help.htm in my project WEB directory to be able to access it in vaadin context. I've 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've tried debugging, copied and past the content of str variable in my web browser I can access the file, and the browser display it correctly. I've also tried with FileResource & ClassResource. Also When I replace the String with http://www.somewebpage.com/ it works, but does not with the above code. How to achieve that?

like image 737
logiframe Avatar asked Dec 07 '11 17:12

logiframe


1 Answers

There are 5 different resources you can choose from in Vaadin depending on the circumstances: ExternalResource, ThemeResource, FileResource, ClassResource, and StreamResource. If you want the file to be bundled with your application, you can either:

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

  • use a ThemeResource (referring to your resource via its relative path to WebContent/VAADIN/themes/yourtheme directory, where you normally put icons and styles)

I'd go with the second approach, because it frees you from finding out the context url.

Read more about resources here and here.

like image 146
n0rm1e Avatar answered Nov 07 '22 02:11

n0rm1e