Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF - session scoped bean shared by browsers on different machines

Tags:

java

session

jsf

We have a search form where the filter is bound to a property on a managed bean (session scope). It's not component binding, its property binding like <h:inputText value="#{searchBean.filter}"/>.

Submitted data from different machines (different sessions, then) is getting mixed. You search "john", and get "mary" just because the guy beside you have just searched "mary". The value of your searchBean.filter is getting his submitted data instead of yours.

I've already googled around a lot and found no solution, just an ocurrence of the same problem.

Have anybody faced this issue already? Any clues?

Thanks!

like image 702
mcrisc Avatar asked Dec 10 '22 18:12

mcrisc


2 Answers

This can have two causes:

  1. The bean is actually in application scope.
  2. The property in question is declared static.

To fix 1), just ensure that it's in session scope.
To fix 2), just remove the illegal modifier.

like image 147
BalusC Avatar answered Feb 09 '23 01:02

BalusC


Solved! Finally. Thanks guys, for your attention!

It was something like what Balus guessed at the first time. It was a static hidden in a dark corner. I had really double, triple checked everything looking for statics, but -- don't ask me why -- someone created a second bean (Foo) which was holding a static reference for SearchBean.

In the JSP, there was an action="#{foo.search}" instead of searchBean.search. Class Foo had a method with the same name as in SearchBean, that was doing no more than a searchBean.search();.

I think pressure for fixing this bug for yesterday didn't allow me to see this trap in the JSP.

like image 42
mcrisc Avatar answered Feb 08 '23 23:02

mcrisc