• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stateful Session Bean - state??

 
Patrick Nolan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a hard time understanding SFSBs. I would like to maintain state in the EJB tier, but it doesn't seem to work that way when the browser is the ejb client. It looks like I have to create a SFSB and store a reference of that in the HTTPSession - is that correct?
For example, with the typical shopping cart example, a user adds a product to his cart. Then, jumps around the site to different pages and decides to add another product. This action should add a product to the same instance of Cart object that he used previously. I can only get this to work if I store a reference to the one SFSB instance in the HTTPSession.
If I don't do it this way, and instead get the SFSB by calling ejbCreate() each time a product is added to the cart, it gives me a newly instantiated Cart object. In other words, It doesn't contain the products that was added earlier...
I am totally confused because books/articles talk about using HTTPSession vs. SFSB for this purpose --- but they appear to me to serve different purposes entirely.
So, is using the HTTPSession to store the SFSB reference the only way to maintain ejb state across multiple page navigations (e.g. http requests).
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're right on track. HTTPSession maintains web server state on behalf of the browser client, SFSB maintain app server state on behalf of the web server as client, so you're right about they are different things. The problem is that only one or two web server clients represent a lot of human users, and the app server can't keep them all straight without help. So the web server often gets a handle to the SFSB and stores the handle in its session. Then it can use the handle to relate a request to a user in a way that the app server understands. Zat make sense?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!