users@glassfish.java.net

Re: how to use sfsb in web tier application

From: Sahoo <sahoo_at_sun.com>
Date: Wed, 05 May 2010 06:22:55 +0530

Everytime you lookup a SFSB in JNDI or every time a SFSB is injected
into a component, a new instance of SFSB is created. Container
instantiates it using the no-arg constructor. The bean can have a
business method documented as part of the bean interface which client
can invoke to initialize the instance with client specific context
before using other business method. e.g., here is an example:

@Stateful public class ShoppingCartBean implements ShoppingCart {
     ...
     private String customer;
     public void startToShop(String customer) {
          this.customer = customer;
     ...
     }
     public void addToCart(Item item) {
          ...
     }
     @Remove public void finishShopping() {
          ...
     }
}

In your web app, when you see create new http session, you can lookup a
ShoppingCart SFSB and call its stratToShop() method to initialize it.

BTW, which document you read that gave you the impression that SFSB
behave like singletons? Have you read EJB chapters in Java EE 6
tutorial? Have you looked at EJB FAQ in glassfish site?

Sahoo

glassfish_at_javadesktop.org wrote:
> Obviously it is!
>
> But my question is how do I create a stateful session [instance] for unique http session?
>
> Looking at past ejbs, they had create... while in 3.x, I'm kind of blind how to initiate a new EJB session. I don't have experience with 1.x or 2.x EJBs.
>
> I just need a working example... I understand EJBs what they are what they 'solve'. Just that I don't have a clue how they are loaded, how they know when it's a new ejb session & stuff.
> [Message sent by forum member 'snovak7']
>
> http://forums.java.net/jive/thread.jspa?messageID=403536
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>