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);