public BookReservation(final PageParameters parameters) {
super(parameters);
RepeatingView repeating = new RepeatingView("repeating");
add(repeating);
ReservationService reservationService = (ReservationService) ApplicationContextProvider.getApplicationContext().getBean("reservationService");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
AuthenticatedSession session = ((AuthenticatedSession)Session.get());
List<ReservationTO> list = reservationService.findReservationsByReader(session.getReader());
if(list != null){
for (ReservationTO reservation : list) {
AbstractItem item = new AbstractItem(repeating.newChildId());
PageParameters pageParameters = new PageParameters();
item.add(new BookmarkablePageLink<Void>("delete", ShowAllReservation.class, pageParameters));
pageParameters.add("reservationid", reservation.getReservationID());
item.add(new Label("author", reservation.getBookTO().getAuthor()));
item.add(new Label("title", reservation.getBookTO().getTitle()));
item.add(new Label("reservationDate", dateFormat.format(reservation.getReservationDate())));
repeating.add(item);
}
}
//delete reservation
StringValue reservationId = parameters.get("reservationid");
if (!reservationId.isEmpty()) {
reservationService.deleteReservation(reservationService.findReservationByID(reservationId.toLong()));
setResponsePage(BookReservation.class);
}
}