3 Replies Latest reply: Mar 28, 2013 6:11 AM by Moazzam RSS

    How can a bean call the method of another bean without declaring

    Moazzam
      The Java EE 6 Tutorial contains a "Duke's Bookstore Case Study Example”. I could not understand following statements of this case study:

      *BookstoreBean.java*

      {code}
      public String add() {
      Book book = getFeatured();
      cart.add(
      book.getBookId(),
      book);
      message(
      null,
      "ConfirmAdd",
      new Object[] { book.getTitle() });

      return ("bookcatalog");
      }
      {code}

      *ShoppingCart.java*

      {code}
      @Named("cart")
      @SessionScoped
      public class ShoppingCart extends AbstractBean implements Serializable {
      {code}

      In BookstoreBean.java, the cart object is not defined anywhere. How can the add method call the add method on cart bean without declaring the cart object. Is it due to context and dependency injection?