how to put data in session variable and get the data in different page in vaadin?

后端 未结 3 1388
囚心锁ツ
囚心锁ツ 2020-12-10 06:52

I think I should use the application scope session to deal with that. But I do not have any experience about that. I tried different ways I got from the internet like:

3条回答
  •  猫巷女王i
    2020-12-10 07:51

    Vaadin is designed to make this problem very easy to solve, and it helps to not think about the normal http request/response cycle here.

    In the typical Vaadin webapp (6 or 7) you have a class that handles the first connection to the webapp (in 7 you extend the UI class). From that first connection all you need to do is store the information you want to keep in any way you would in a normal app -- variable, map, list, plain old java object (POJO), etc. Say you use a POJO. That object is just like any other Java object. Hold it in a variable accessible by any object that needs it. If you've added any kind of interactivity to the webapp, the user will 'enter' the application again through that interactive component (say a Button listener). From that button listener you can access the POJO you created earlier in the user's 'session.'

    That's it. It's actually surprisingly simple, and doesn't involve you ever touching http (unless you want to later). And certainly not threadlocals for this level of storage.

提交回复
热议问题