0

I was making some test with my JSF-app and when I tried it in the same web-browser on different tabs, in all tabs the last session was present.

How can I prevent this?

BRabbit27
  • 6,333
  • 17
  • 90
  • 161

1 Answers1

5

That isn't possible without hacking/changing the browser. But this really shouldn't matter. If that causes unintuitive behaviour in your JSF application (e.g. data of one tab is been redisplayed in another tab), then you were apparently storing view scoped data in session scoped beans. You should store view scoped data in view scoped beans instead.

Or if it is purely intended for testing purposes (i.e. you just wanted to test physically separate user sessions), then you should use physically separate browsers. E.g. one Firefox and one Chrome.

Or if you absolutely need to have "one user session per tab/window", then store the logged-in user in a view scoped bean instead of a session scoped bean and exclusively use ajax postbacks to navigate through pages (SPA - Single Page Application).

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Well, the userBean is the one that has a Session Scoped, and some of my operations in the next page (which has a uploadBean as ViewScoped) need that info of the user to render or not other components. Maybe I can't have various sessions in same browser (diff tabs) but, is there a way to prevent the login of different users? I mean how to check if a session is already created and by that skip the login page. Is that doable? – BRabbit27 Nov 16 '11 at 01:13
  • I have no idea what you mean with "prevent the login of different users". What's the functional requirement? Do you want to allow only one login **applicationwide**? – BalusC Nov 16 '11 at 01:16
  • I mean, check if there's already a session going on, if yes, just skip the login page. – BRabbit27 Nov 16 '11 at 01:18
  • That's already been answered in your previous question. Note, please don't confuse "a session" with "a logged-in user". A session can perfectly exist without ever having a logged-in user. To learn about "under the covers" working, please read http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading/3106909#3106909 Yes, that applies to JSF as well. JSF is built on top of Servlet API. – BalusC Nov 16 '11 at 01:19
  • Nope. not app-wide. Just for that browser. – BRabbit27 Nov 16 '11 at 01:20
  • Thanks I'll check that out. And no, I'm not confusing those terms, it's just that my login page is what makes the userBean be in session scope. Sorry if I bothered you, I'm very very new to this tech. Thanks. – BRabbit27 Nov 16 '11 at 02:24
  • This might help: (http://superuser.com/questions/60931/how-to-maintain-different-active-sessions-in-single-firefox-and-internet-explore) – Kevin Rahe Jan 16 '12 at 20:49