File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Managed Benan Instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Managed Benan Instance" Watch "Managed Benan Instance" New topic

Managed Benan Instance

Chris Jebaraj
Ranch Hand

Joined: Sep 19, 2003
Posts: 34
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.

JebaRaj.<br /> MCP, SCJP 1.5 <br />----------------------------<br /> THOUGH TIMES TEACH TRUST. <br />----------------------------
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

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.

An IDE is no substitute for an Intelligent Developer.
Chris Jebaraj
Ranch Hand

Joined: Sep 19, 2003
Posts: 34
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?
I agree. Here's the link:
subject: Managed Benan Instance
It's not a secret anymore!