private List<BookTO> listSelectedBook = new ArrayList();
public AddBorrow(final PageParameters parameters) {
super(parameters);
ReaderService readerService = (ReaderService) ApplicationContextProvider.getApplicationContext().getBean("readerService");
final BookService bookService = (BookService) ApplicationContextProvider.getApplicationContext().getBean("bookService");
borrow = new BorrowTO();
Form<?> form;
form = new Form("form") {
@Override
protected void onSubmit() {
BorrowService borrowService = (BorrowService) ApplicationContextProvider.getApplicationContext().getBean("borrowService");
if (borrow.getBorrowID() == null) {
borrow.setBorrowDate(new Date(System.currentTimeMillis()));
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(System.currentTimeMillis()));
cal.add(Calendar.MONTH, 1); // add 1 month
borrow.setExpirationDate(cal.getTime());
if (selectedBook != null) {
listSelectedBook.add(selectedBook);
}
if (selectedBook2 != null) {
listSelectedBook.add(selectedBook2);
}
if (selectedBook3 != null) {
listSelectedBook.add(selectedBook3);
}
if (selectedBook4 != null) {
listSelectedBook.add(selectedBook4);
}
if (selectedBook5 != null) {
listSelectedBook.add(selectedBook5);
}
if (selectedBook6 != null) {
listSelectedBook.add(selectedBook6);
}
for (int i = 0; i < listSelectedBook.size(); i++) {
for (int j = i + 1; j < listSelectedBook.size(); j++) {
if (listSelectedBook.get(i).equals(listSelectedBook.get(j))) {
listSelectedBook.remove(listSelectedBook.get(j));
j--;
}
}
}
borrow.setTitlesTO(listSelectedBook);
borrowService.createBorrow(borrow);
}
setResponsePage(ShowAllBorrow.class);
}
};
add(form);
List<ReaderTO> readers = readerService.findAllReaders();
DropDownChoice choiceReaders = new DropDownChoice("reader", new PropertyModel(borrow, "readerTO"), readers);
form.add(choiceReaders);
List<BookTO> books = bookService.findAllAvailableBooks();
DropDownChoice choiceBooks = new DropDownChoice("title", new PropertyModel(this, "selectedBook"), books);
form.add(choiceBooks);
DropDownChoice choiceBooks2 = new DropDownChoice("title2", new PropertyModel(this, "selectedBook2"), books);
form.add(choiceBooks2);