0

What I want is different different session bean per tab/ window. I know session bean works but I want to create new sessionbean for new tab. Below is reason why I want new session bean.

Suppose on page1, I have list of users. On clicking user, I get details of user in page2.

Now suppose I have two tab. In both pages I have page1.xhtml. On tab1, I clicked on User A. I see details of User A on page2.xhtml Now I come on tab2. On tab2, I clicked on User B. I see details of User B on page2.xhtml Problem is here now. Now I come back to tab1 and refresh the page2.xhtml, I see User B details which is incorrect because earlier I was seeing User A details.

Hence what I want is new sessionbean per new tab/ window.

Is there any way to create new sessionbean per tab/ window? In primefaces or icefaces maybe?


I thought ViewScope was solution, but that was not. Referring BalusC article.

@ViewScoped: a bean in this scope lives as long as you're interacting with the same JSF view in the browser window/tab. It get created upon a HTTP request and get destroyed once you postback to a different view.


With SessionBean, I meant Java/ JSF managed session managed beans and not browser session (history).

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • I think the behavior is caused by your Browser, not the Backend. You can use the Internet Explorer for example for open a new session, however it will open it in a new Window. Tabs always belong to the same session. Please correct me if I am wrong. – Sven Plath Feb 27 '13 at 08:15
  • @SvenPlath : With session bean, I meant java/ jsf sesssionbean and not browser session (history)... – Fahim Parkar Feb 27 '13 at 08:21
  • @FahimParkar You do not need to store selected user's id in the session, because it does not essentially belong to the session, and usually people store selected user's id as a view parameter, so that refreshing the page triggers another request that leads you back to the same page (`user.xhtml?id=1`). – skuntsel Feb 27 '13 at 09:30
  • @skuntsel : we should not pass id in URL... if I do id=2 then sm1 else password would be changed... this way anonymous user will have access to all data... – Fahim Parkar Feb 27 '13 at 10:12

2 Answers2

1

If you are using CDI Conversation scope could help.

From the Java EE docs: ConversationScoped

These tutorials might help.

  1. CDI Conversations Part 1
  2. CDI Conversations Part 2

Hope this helps !!!

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
baba.kabira
  • 3,111
  • 2
  • 26
  • 37
0

@ViewScoped is the solution to this problem, indeed. The problem looks to be that you're setting the UserX data (id, detail or something else) into session when navigating from page1.xhtml and then loading this session data in page2.xhtml. So, if this is your current situation, not even CDI @ConversationScoped will help you (since it uses cid query string param).

In order to solve this, you should make a GET request of your page2.xhtml and send the userId (or another useful parameter) to recover the details of your UserX.

More info:

Note that you can encrypt the parameter (let's say, the ID) to add some security to your parameters. Please refer to the second proposed link in order to achieve this.

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332