Hi,
I’m new both in Vaadin and Eclipse, so please forgive me for such an elementary question. I got two problems:
I want to have a static logout page logout.html in project named VaadinHelloWorld in folder /static. The logout process will be initiated through pressing a Button with his own listener:
public void thirdButtonClick (Button.ClickEvent event) {
setLogoutURL("/static/logout.html");
System.out.println(mainWindow.getApplication().getLogoutURL());
mainWindow.getApplication().close();
}
(Just for proof, I got every time the text “/static/logout.html” in console after pressing the button.)
I have made a folder named “static” under the project and placed a static html file named logout.html. However, every time i get an error 404 with “The requested resource (/static/logout.html) is not available.” message. So, what’s the catch? Should I place the folder “static” place somewhere else?
my second problem is also in relation with the static resorces. This time, I have tried to load an image as a logo. The class -the only one what I currently use - is in package com.example.vaadinhelloworld as follows:
package com.example.vaadinhelloworld;
import ....
public class VaadinhelloworldApplication extends Application implements
com.vaadin.ui.Button.ClickListener {...}
The code which WORKS for getting the image is :
ClassResource res = new ClassResource("/com/example/vaadinhelloworld/pics/logo.png", mainWindow.getApplication());
mainWindow.addComponent(new Embedded ("",res));
Of course, I get the proper directory structure under Java resources/src with the file logo.png. It works fine, but I’m not able to place the picture somewhere else, for example into folder “static” mentioned above. If I do so, I will get no error, no exception, just the picture does not appear. I feel that the catch may be the same as above, but I’m not sure. Anyway I wil greatly appreciate any hint.
Greetings, Kornel
Static content is always served from the WebContent folder in your project root, so you should move your static folder here. Everything else is hidden.
There are a few ways to make this happen: You can use an ExternalResource to serve the image from your static folder, or a ThemeResource to serve it from a theme folder. In the latter case, you need to create your own theme and theme folder (this is very easy if you just extend the default Vaadin theme, Reindeer. There is a chapter about this in the Book of Vaadin) and set the theme name for applications.
Hi, I tried the hints, they do not work. For logout page i get still 404, and for resorce (this time Externalresource) i get no picture, no error, no exception.
The folder structure is shown on next picture:
I played around with this a while, but couldn’t get the resources to load without mapping the application to a non-root url… Maybe someone else can chime in here?
it was taken a day or so to realise the catch: you must have /VAADIN/* mapping mandatory in such cases, the /static/* mapping itself does not work!
After some googlework, it seems that others had similar problems:
Adding static content
Anyway, I wish you to say thank for your precious help.