Win a copy of Reactive Design Patterns this week in the Functional Programming forum
or Learn Linux in a Month of Lunches in the Linux forum!
    Bookmark Topic Watch Topic
  • New Topic

SessionScoped bean created several times

 
Jesus Schneider
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello all.

I work with Eclipse Mars.2, the system has Java 1.8 update 102 for 64bits but this project uses Java 1.7, JSF Mojarra 2.2, Primefaces 6.0 and Tomcat 7.0.53/7.0.54/8.0.1/8.0.11.
I have created the smallest test project in order to show the problem, and ALL its files will be copied following this description.

The test project consist of 2 pages created with templates, with a menubar on top to browse and a selectOneMenu also on top to select the current language.
The current language is stored in a variable in a session bean which is used in both pages and is refreshed every time we change the selectOneMenu.
When I run the APP on Tomcat 7.0.53 / Tomcat 8.0.1 or lesser versions it works percfectly, the SessionScoped bean is created just once and the value is kept correctly stored.
The problem happens when I run the same APP in Tomcat 7.0.54 / Tomcat 8.0.11 or later versions, in such case the SessionScoped bean is created everytime it is used, and as the current language value is initialized it is always set to the default ( english ).

I have researched a lot and asked in several sites but without any luck.
Maybe someone can iluminate me?
Thanks a lot in advance!!

Following the test project files:



template.xhtml



index.xhtml



page2.xhtml



head_view.xhtml



foot_view.xhtml



index_view.xhtml



page2_view.xhtml



headBB.java



indexBB.java



Language.java



languageConverter.java



sesion.java



messages_en_GB.properties



messages_es_ES.properties



applicationContext.xml



faces-config.xml



web.xml



pom.xml



Thanks a lot if you have read all the above! :-)





 
Tim Holloway
Saloon Keeper
Posts: 18388
58
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Sorry. The only way I'd be plodding through a raw code dump like that is if someone was paying me full salary. Not many other people would either. Please simplify before posting stuff like this. If it can't all fit on one screen, the odds that you'll get an answer drop significantly.

I can tell you this. A Session scoped bean is simply a Serializable POJO that either your program logic or JSF's Managed Bean subsystem constructs and then stores under a name in the HttpSession object map. Since the name is the item key, that means that one and only one object of that name can exist for the session. Any object previously stored under that name will therefore become de-referenced, and if nothing else references it, will be eligible for garbage collection.

JSF will not construct a session object if the object already exists. Session-scoped objects are not automatically removed from the session. For that, you'd need View Scope. So the logical conclusion is that you yourself are doing something that removes the bean from the session.
 
Jesus Schneider
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks a lot for your suggestions!
I think that I will re-post this issue with a lot less code.
Regarding the idea of me performing some action that removes the sessionscoped bean from HTTP session, it sounds logical to me but I don't perform (on purpose) any action to do that...
Thanks a lot, really!
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!