Vaadin 7 - Set Login Data into VaadinSession attributes

Hi all,
I’m currently using Vaadin 7 for creating a RIA.
I’m facing the Login problem: after a user has been authenticated through a LoginView, he should visualize a MainView with his name.

The entry point is a UI Observer class that has a Navigator for navigating from LoginView to MainView (both Observable).
Once authentication is correctly completed LoginView tries to store user data as a VaadinSession attribute with the following code:


VaadinSession.getCurrent().setAttribute(“name”, name);

then UI navigates to MainView and tries to get the name of the user with:


VaadinSession.getCurrent().getAttribute(“name”);


but it gets a null value
:rolleyes:.


Does anyone know why?

Thanks.

Hi all,
I try to explain better.

I’m currently using Vaadin 7 for creating a RIA and I’m designing the Login functionality.

The application design is simple:
A UI class performs navigation beetwen different View classes. In particular, the first displayed View is a LoginView class and after a user has been authenticated the UI class redirects the user towards a MainView.

After authentication I’d like to set User data (eg name and surname) into the session and display it always (no matter what specific view) on the top right corner of the Web Application.

As a begginner I read the Vaadin Book and I firstly used the scheme illustrated in chapter 11th https://vaadin.com/book/-/page/advanced.global.html, but it doesn’t seem to work as expected, probably because I’m using View navigation scheme.

So I use the following approach:

Once authentication is correctly completed LoginView tries to store user data as a VaadinSession attribute with the following code:


VaadinSession.getCurrent().setAttribute(“name”, name);

then UI navigates to MainView and tries to get the name of the user with:


VaadinSession.getCurrent().getAttribute(“name”);

but it gets a
null value
.


Does anyone know why? I appreciate any help
.

Thank you.

Hi,

You probably need to set your attribute in VaadinSession before trying to access it :slight_smile:

Are you calling
VaadinSession.getCurrent().getAttribute(“name”);
during the initialization of your MainView object ?

Hi Philippe,
thank you for your interest.

If authentication is correct LoginView class sets the attribute into the session with:


VaadinSession.getCurrent().setAttribute(“name”, name);

and executes the navigation towards the MainView.

During the initialization, MainView uses:


VaadinSession.getCurrent().getAttribute(“name”);

to access to the previously set attribute, but it gets a null Object.

Now it seems that a VaadinSession.getCurrent() returns the same VaadinSession object but with default value initialized fields.

Any suggestion?

Thanks