The example is quite old, and there is a note at the beginning about things that should be done differently:
Nevertheless, I believe it should work. Check your TransactionListener (or HttpServletRequestListener) - if your application implements one, it should be called automatically if I remember correctly. Check that the listener is actually called, and sets the thread local variable.
There are also other libraries or frameworks on top of Vaadin that handle authentication, including e.g.
AppFoundation .
Is it possible to describe a common usefull login example on vaadin.com? The example that’s published is corrupt, outdated (it dows not work), and the appfoundation.jar do not provide a full example. I should like to see a correct example. A login is a common example that everybody wants.
I studied the example meanwhile. When you try to use it by the refered example application, it requires to use the FacadeFactory. And that example has not been described. It looks to me that the several discussions longer then writing a proper tutorial. It is not working yet. I tried several things. Personally I think this part should be documented at examples. It is a must have feature (FacadeFactory and authentication).
I implemented the code in the article you linked into an application myself about two months ago and noticed that the code did not even compile. I tried to fix all the errors in the article but I clearly missed something. Looking at it, I guess it could work if you add setCurrent(this); as the first row of the application’s init -method. Please test it out and report back here, so that I can update the article accordingly.
As the comment says at the beginning of the article (added by me :)), HTTPServletRequestListener should be quicker and leaner. Here is about what you need to implement it into your applicaiton
public class MyApplication extends Application implements HTTPServletRequestListener
private static ThreadLocal<MyApplication> currentApplication = new ThreadLocal<MyApplication>();
@Override
public void init() {
set(this);
...
}
/**
* @return the current application instance
*/
public static MyApplication get() {
return currentApplication.get();
}
/**
* Set the current application instance
*/
public static void set(MyApplication application) {
if (get() == null) {
currentApplication.set(application);
}
}
@Override
public void onRequestStart(HttpServletRequest request, HttpServletResponse response) {
currentApplication.set(this);
}
@Override
public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) {
currentApplication.set(null);
}
The documentation for using the FacadeFactory (and the persistence module in general) can be found
here . The live demo doesn’t yet have the persistence module described, as it is still a work-in-progress.
Otherwise, just use form-based login and have users log in before getting to the Vaadin application. Personally, I like the idea of not using form-based auth.