6 Replies Latest reply on Jan 29, 2011 12:31 PM by Ara Minosian

    Bean created twice

    Arun Gupta Newbie
      For a simple application, accessing http://localhost:8080/HelloConversation/faces/index.xhtml creates ShoppingCart twice. Any idea ?

      Utility class is ...

      @Named("util")
      @ConversationScoped
      public class ConvUtil implements Serializable {
           @Inject ShoppingCart cart;

           public ShoppingCart getCart() {
               return cart;
           }
      }

      index.xhtml has ...
                       <h:inputText value="#{util.cart}" title="name" id="name"
                                    required="true" />


      ShoppingCart is ...

      @Named
      @ConversationScoped
      public class ShoppingCart implements Serializable {
           public ShoppingCart() {
               System.out.println("Creating shopping cart ..." + Calendar.getInstance().get(Calendar.MILLISECOND));
           }

      }

      At least the log messages like:

      INFO: Creating shopping cart ...264
      INFO: Creating shopping cart ...265

      are printed.

      Tried changing the scope of ShoppingCart to RequestScoped but still the same. Changed @Named to @javax.faces.bean.ManagedBean on ShoppingCart.

      What am I not doing correctly ?

      -Arun