-2

I am working with Spring boot, security and Thymeleaf: I have a table with the data from a database, I have created filters, when I select a value, the table show the data filtered, so I want to implement multiple filters and keep the value selected when I change the page. So I had the idea to create variables where I can keep the selected values:

private Optional <TRACKING_CARD> typeSelected;

private Optional <STATUS> statusSelected;

private Optional <Boolean> flagStaff;

and when I select the values:

typeSelected = filter.getType();
statusSelected = filter.getStatus();
flagStaff = filter.getFlag();

But the problem is that the variables are global, so if more than one user is logged in the same time, they share the value of the variables.

How can solve this?

Thanks

DvMg
  • 1
  • 1
  • 2
    Does this answer your question? [How to use Session attributes in Spring-mvc](https://stackoverflow.com/questions/18791645/how-to-use-session-attributes-in-spring-mvc) – vicpermir Feb 19 '20 at 17:48

2 Answers2

0

You need to initialise them separately for all users or instances. So every user will have their own instance. Even filters need to be initialise with user login.

Different instances for users will solve this problem.

Bhupinder Singh
  • 3,355
  • 2
  • 11
  • 14
0

you can not persist data like this way. If you want to share the data among the others you can declare the variable static which is to be alive and same instance will be shared.

In your case, you don't need to worry about it as each request will have separate filters.

Desi boys
  • 29
  • 3