getBaseDirectory after session.close


i am displaying an image resource on my application scresns using VaadinService.getCurrent().getBaseDirectory() method. The issue is once I close a session using VaadinSession.getCurrent().close(), the VaadinService.getCurrent is returning null and hence once I close the session, the images are not getting displayed until I referesh the browser. How do I avoid this.


Of course; when you close the session, you are telling the servlet container that you don’t need anything from that session anymore. What exactly are you showing, and why? Why are you calling session.close()?

I need to inavlidate the session and remove all atrributes from it. That is why I am calling session.close.

I come from a JSF background and I might be doing it wrong.

OK, you want to invalidate the session. But why do you want to use the session afterwards? What are you showing the user?

As per the screen flow there are

  1. Main screen which is the landing page
  2. Login is present as a lonk on the Main screen and once logged in the user details are stored in session
  3. There are bunch of functional screens with a log out option on each of these screens
  4. Once logged out, the session has to be invalidated and it has to return to Main screen on step 1

On all the screens there is a Logo on Top which is loaded as a Image Component using file resource with base directory obtained fro mVaadinService.getCurrent().getBaseDirectory(). Now when I invalidate the session and redirect to home page, VaadinService is null and the image is not being displayed.

The way I would do this is to actually reload the page on logout; you get a new session, and the image will work. To reload programmatically, call:

UI ui=UI.getCurrent();
ui.getSession().invalidate(); //or whatever this was
ui.getPage().setLocation(“”); //will reload the app

Of course, if you put the image in a theme folder and use a ThemeResource, it would work without the reload.

Thanks for the suggestion. It worked.