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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With