Global Vars

We use Vaadin with Netbeans. In this context, we are looking for a demo for a working session management. We want to put some data in global variables that are used in the program. Static vars fall out according to the documentation. For a reference, or a demo, we would be grateful.

If your global variables are application instance specific, then take a look at the
ThreadLocal pattern

If your global variables shared across all applications, then statics are fine as long as your application is running inside one JVM.

Hi, thanks for the quick reply! -_-

In jsp when I can start a session with “session = request.getSession (true)” to assign an arbitrary value.
For example, with “session.setAttribute (” user “, username);”
Reading is with “user = request.getParameter (” user “);” possible.
Relatively simple.

This is also possible in this context?

Technically, that would be possible, but in practice quite difficult. It sounds more and more like the ThreadLocal pattern being something you’d want to use. Here is another variation of the ThreadLocal pattern:

Thanks for the help!
I have the use of

“public class app extends Application implements HttpServletRequestListener {
private static ThreadLocal local = new thread ThreadLocal ();”

derived and write a class of the variable with getter and setter.
I call it “userData”.

With the assignment "app.[b]
/b.setUserData (name, firstname, User_ID, …). can read and assign the values ​​corresponding to the current session.

This seems to work …:grin:

You can implement
in your application to get the servlet request, and from there get the the http session, and do the exact same thing. But since the whole state of your application is already stored in the session, this seems like more work than you need. Just set a field in your application class and its value will be set for the length of the session.