示例#1
0
  public String addItemWithAjax() {

    Book book = bookManager.getBookByIsbn(bookId);

    if (loggedCustomer != null && theCart != null) {
      if (book != null) {
        theCart.addItem(book.getIsbn());
        String message =
            ajaxContentProvider.getCartUpdateAsJson(
                "ok", book.getTitle(), theCart.getCount(), null);
        inputStream = new ByteArrayInputStream(message.getBytes());
        return ActionSupport.SUCCESS;
      } else {
        error =
            ajaxContentProvider.getCartUpdateAsJson(
                "ko",
                null,
                null,
                messageProvider.getMessage(
                    "web.error.book.unknown", new Object[] {bookId}, null, null));
        inputStream = new ByteArrayInputStream(error.getBytes());
        return ActionSupport.ERROR;
      }
    } else {
      error =
          ajaxContentProvider.getCartUpdateAsJson(
              "ko",
              null,
              null,
              messageProvider.getMessage("web.error.purchase.login", null, null, null));
      inputStream = new ByteArrayInputStream(error.getBytes());
      return ActionSupport.ERROR;
    }
  }
示例#2
0
  public String addItem() {

    Book book = bookManager.getBookByIsbn(bookId);

    if (loggedCustomer.getId() != 0 && theCart != null) {
      if (book != null) {
        theCart.addItem(book.getIsbn());
      }
      return ActionSupport.SUCCESS;
    } else {
      error = messageProvider.getMessage("web.error.purchase.login", null, null, null);
      return ActionSupport.ERROR;
    }
  }