Search in sources :

Example 1 with OnEvent

use of org.apache.tapestry5.annotations.OnEvent in project tapestry5-hotel-booking by ccordenier.

the class Book method validateBooking.

@OnEvent(value = EventConstants.VALIDATE, component = "bookingForm")
public void validateBooking() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    if (booking.getCheckinDate().before(calendar.getTime())) {
        bookingForm.recordError(messages.get("booking_checkInNotFutureDate"));
        return;
    } else if (!booking.getCheckinDate().before(booking.getCheckoutDate())) {
        bookingForm.recordError(messages.get("booking_checkOutBeforeCheckIn"));
        return;
    }
    userWorkspace.getCurrent().setStatus(true);
}
Also used : Calendar(java.util.Calendar) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Example 2 with OnEvent

use of org.apache.tapestry5.annotations.OnEvent in project tapestry5-hotel-booking by ccordenier.

the class View method startBooking.

/**
     * Start booking process.
     * 
     * @param hotel
     * @return link to the current hotel booking
     */
@OnEvent(value = EventConstants.SUCCESS, component = "startBookingForm")
Object startBooking(Hotel hotel) {
    User user = (User) dao.find(User.class, authenticator.getLoggedUser().getId());
    userWorkspace.startBooking(hotel, user);
    return Book.class;
}
Also used : User(com.tap5.hotelbooking.entities.User) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Example 3 with OnEvent

use of org.apache.tapestry5.annotations.OnEvent in project tapestry5-hotel-booking by ccordenier.

the class Signup method proceedSignup.

@OnEvent(value = EventConstants.SUCCESS, component = "RegisterForm")
public Object proceedSignup() {
    User userVerif = crudServiceDAO.findUniqueWithNamedQuery(User.BY_USERNAME_OR_EMAIL, QueryParameters.with("username", username).and("email", email).parameters());
    if (userVerif != null) {
        registerForm.recordError(messages.get("error.userexists"));
        return null;
    }
    User user = new User(fullName, username, email, password);
    crudServiceDAO.create(user);
    try {
        authenticator.login(username, password);
    } catch (AuthenticationException ex) {
        registerForm.recordError("Authentication process has failed");
        return this;
    }
    return Search.class;
}
Also used : User(com.tap5.hotelbooking.entities.User) AuthenticationException(com.tap5.hotelbooking.security.AuthenticationException) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Aggregations

OnEvent (org.apache.tapestry5.annotations.OnEvent)3 User (com.tap5.hotelbooking.entities.User)2 AuthenticationException (com.tap5.hotelbooking.security.AuthenticationException)1 Calendar (java.util.Calendar)1