0

First question:

I have two windows (of IE), with the first window I'm making a search on a screen and then, I'm making another search with the second window. After that, I'm losing one of my two sessions and here my question, is it possible to have 2 windows that make a different search and which have their own results in their own session or is it impossible ?

Second question:

<managed-bean>
<managed-bean-name>searchBean</managed-bean-name>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
    <property-name>resultBean</property-name>
</managed-property>

<managed-bean>
<managed-bean-name>resultBean</managed-bean-name>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
    <property-name>tabMap</property-name>
    <map-entries>
        <key-class>java.lang.Integer</key-class>
        <map-entry>
            <key>0</key>
            <value>#{firstTabBean}</value>
        </map-entry>
        <map-entry>
            ...
        </map-entry>
    </map-entries>
</managed-property>

<managed-bean>
<managed-bean-name>firstTabBean</managed-bean-name>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
    <property-name>resultBean</property-name>                   
    <value>#{resultBean}</value>
</managed-property>

In fact, in my resultBean (bean of my screen where the results are showed), I have a lot of tabs with others beans. But if my "resultBean" is request-scoped, I have to change the scope of all my "tabBean" because I can't have a session-scoped bean with request-scoped bean in the < managed-property>, the scope is shorter and I have an exception.

xAngy
  • 27
  • 1
  • 9

1 Answers1

1

Two windows doesn't necessary mean two distinct sessions, so that is normal that the search is overriden (there is only one real session).

What you are searching for is a View Scope rather than Session Scope. In View Scope, the search will exists until you are posting to another View. When you open a new window (or tab), it is creating a new View Scope, so you can keep as many searchs as you want.

In JSF 2.0 I would recommand putting the bean in ViewScoped but in JSF 1.2 this answer could help you to do almost the same.

Regarding your older posts, it seems that you are using RichFaces, so you could be interrested by a4j:keepAlive, read more in this article.

Community
  • 1
  • 1
Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • That works only with request scope (request) or can I use a session-scope ? – xAngy May 27 '13 at 07:53
  • It works only with RequestScoped, it will _transform_ it in ViewScope – Alexandre Lavoie May 27 '13 at 07:58
  • Hmmm... All the managed beans are in session scope in the application... it's a little bit annoying :( – xAngy May 27 '13 at 08:11
  • You only have to do it on beans used for searching ie : the bean that actually contain results and/or search options. – Alexandre Lavoie May 27 '13 at 08:13
  • About that, if I need a bean (in the session scope) as property in my request-scoped bean. There is a problem I think. => "Property navigationBean references object in a scope with shorter lifetime than the target scope view" – xAngy May 27 '13 at 09:48
  • If your request bean (ported to view scope) need the session scope, I don't think that will cause problem. – Alexandre Lavoie May 27 '13 at 09:55
  • @xAngy you are welcome, mark it as answered so other users will know it! – Alexandre Lavoie May 27 '13 at 14:06
  • Hmmm in fact... it works with 2 pages but I have a lot of pages/beans and it's unmaintainable. I have to change all my beans's scope (in request scope instead of session scope) and I have to add a lot of "" in almost all my .jsp... arg... :/ And I think that it's impossible to maintain the application with my beans in a request scope :/ – xAngy May 28 '13 at 08:22
  • @xAngy You only have to migrate search related beans, or there is something I don't understand! :) – Alexandre Lavoie May 28 '13 at 08:23
  • I would like to show you a little part of my code but it's too long for the comment :( – xAngy May 28 '13 at 08:40
  • @xAngy you can edit your Question, also it is better to do it so! – Alexandre Lavoie May 28 '13 at 08:41
  • @xAngy you don't need more than one bean for tab since you are emulating ViewScope, this bean will have more than one instance once you do more than one search. – Alexandre Lavoie May 28 '13 at 08:52
  • When I say "tabs", that means: others screens into a screen. I don't know if we understand each other :p So, I need more than one bean to manage all the tabs/screens. – xAngy May 28 '13 at 09:00
  • Yes I understand like HTML/JavaScript tabs, in that case you can have more than one bean or only one containing data for each tab. – Alexandre Lavoie May 28 '13 at 09:02