Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

SessionScoped bean created several times

Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:












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

Saloon Keeper
Posts: 24863
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic