Пример #1
0
  /** Добавление записи */
  public void addItem() {
    Item item = new Item();
    item.setBookOrder(newBookOrder);
    item.setBook(selectedBook);

    boolean bookHasAdded = false;
    for (Item i : this.newBookOrder.getItems()) { // Проверка на уже
      // добавленные
      if (i.getBook().getId() == selectedBook.getId()) {
        bookHasAdded = true;
        break;
      }
    }

    if (!bookHasAdded && !selectedBook.isBlocked() && !selectedBook.isReads())
      this.newBookOrder.getItems().add(item);
  }
Пример #2
0
  public void deleteNewBook() {
    try {

      Item ti = null;

      for (Item i : newBookOrder.getItems())
        if (i.getBook().getId() == currentNewItem.getBook().getId()) {
          ti = i;
          break;
        }

      newBookOrder.getItems().remove(ti);

      for (Item i : newBookOrder.getItems()) System.out.println("*>>>" + i.getBook().getTitle());

    } catch (Exception e) {
      e.printStackTrace();
      FacesContext.getCurrentInstance()
          .addMessage(
              null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error: ", e.getMessage()));
    }
  }