• Post Reply 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Managed Benan Instance

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I specify the scope of the Managed bean as "Session" in faces-config.xml, then I believe the container will create "One" instance of the MB per Session. Is that correct??

Ok, if that is correct. I am totally confused here.

Here is my managed bean,


I deployed the enterprise application and run the App Server. Now, When the first Session is created ( lets say, first user logged in ), I am getting this S.O.P statement printed in the console. After that how many ever sessions created ( ie, how many ever users logged in ), I don't see the S.O.P statement in the console.

Since I specified the scope as "Session", I am expecting the S.O.P statement per Session Creation.

Am I missing something here??? Any thoughts.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can see two possibilities.

1. If you're expecting multiple sessions to be created, but you're not accessing the app from multiple computers, you won't get them. A session created in one browser window will apply to all the other browser windows. (exception, if you're running Internet Explorer and Firefox, IE will have one session and Firefox will have one session - the session is defined in each brower's cookie collection unless you disable cookies).

2. System.out.println is a very untrustworthy way to output text to a webapp console. It's not part of the standard, so not only do different appservers route it differently, the same appserver on different OS's may not route System.out the same. For anything more than a quick-and-dirty debug, it's better to use one of the logging frameworks.

Specifically, what I'm saying is that it's possible that your other println's are getting lost somewhere. But since they do tend to show up eventually, I'd consider case #1 as the likely problem.
 
Chris Jebaraj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Regarding point #2, I totally agree with you. Just want to notice how many times the Constructor of the BB is called, i used SOP.

Your point #1 is valid. If that is the case, the App Server creates BB instance per Browser Type ( thinks that each browser type (IE or Firefox) instance is a new session ). I am confused here.

Ok, lets take the normal "Shopping Cart Application". I assume each User login will be considered as new Session. But this contradict to your Point #1. If i dont close the browser window and login-logout with five different user, then will the App Server creates only one BB instance??

If that is correct, then i am forced to believe that the definition of session by App Server is different from what we normally consider in Shopping Cart Application. Is that true?

So, the managed-bean-scope that we are defining in faces-config.xml file is more for App Server's session definition and not the sessions (HttpSession) that we create,manage,destroy in the Application. Is that corret?

Can you clear me on this, I think i have missed out some basic knowledge towards the Session?
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic