vendredi 24 juin 2016

Checking if a session variable exists in Vaadin

VaadinSession.getCurrent().getAttribute("name")
&
VaadinSession.getCurrent().setAttribute("name", "actual nameson")

vs

getSession().getAttribute("name", username);
&
getSession().setAttribute("name", username);

are either of these correct methods to use Vaadin's Session management? I cannot find understandable documentation on getting and setting a session in Vaadin.

My current problem: if I try to Get a session variable, I get a nullpointerException, I tried to swallow it and continue but this makes Vaadin implode.

Is there a safe way to check if a Vaadin session (and specific variable) is set?

Do I have to initialize a session before I can use the variables?

more specifically, I want to check if a session exists before a user is redirected to the login screen. if the user is not logged in, the check throws a nullpointerException so a user who is not logged in cannot load the loginForm.

question @ How to get all sessions in Vaadin is not related to my problem.

one more thing

boolean isLoggedIn = getSession().getAttribute("user") != null;

does not make Vaadin implode, so I am probably just doing a Java Fail™

any help would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire