2 Replies Latest reply on Jan 19, 2010 4:30 PM by Youssef El Maroufy

    Stateful not keep data

    Youssef El Maroufy Newbie

      Hi

      I hope i'm in the correct sub-furum

      I have a problem with Stateful that do not keep data between methods calls;

      @Stateful
      public class ShoppingCart implements ShoppingCartLocal {
      
           private List<CartItem> cartItems;
      
           public List<CartItem> getCartItems() {
                return cartItems;
           }
      
           @PostConstruct
           public void initialize() {
                System.out.println("<--Construct-->");
                cartItems = new ArrayList<CartItem>();
           }
      
           @PreDestroy
           public void clear() {
                System.out.println("<--Destroy-->");
                cartItems = null;
           }
      
      }
      

      the method initialize() is executed on each call !

       

      I'm using JBoss 5.1, and the Stateful is injected in a Managed Bean

       

      public class ProductBusinessDelegate {
           @EJB
           ProductBusinessLocal productBusiness;
           @EJB
           ShoppingCartLocal shoppingCart;
      
           public List<CartItem> getCartItems(){
                return shoppingCart.getCartItems();
           }
      
           public ProductBusinessDelegate() {
           }
           
      }
      

       

      Thanks