Search in sources :

Example 1 with Component

use of org.apache.tapestry5.runtime.Component 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 Component

use of org.apache.tapestry5.runtime.Component 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 Component

use of org.apache.tapestry5.runtime.Component 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)

Example 4 with Component

use of org.apache.tapestry5.runtime.Component in project tapestry5-hotel-booking by ccordenier.

the class AuthenticationFilter method dispatchedToLoginPage.

private boolean dispatchedToLoginPage(String pageName) throws IOException {
    if (authenticator.isLoggedIn()) {
        // Logged user should not go back to Signin or Signup
        if (signinPage.equalsIgnoreCase(pageName) || signupPage.equalsIgnoreCase(pageName)) {
            Link link = renderLinkSource.createPageRenderLink(defaultPage);
            response.sendRedirect(link);
            return true;
        }
        return false;
    }
    Component page = componentSource.getPage(pageName);
    if (page.getClass().isAnnotationPresent(AnonymousAccess.class)) {
        return false;
    }
    Link link = renderLinkSource.createPageRenderLink("Signin");
    response.sendRedirect(link);
    return true;
}
Also used : Component(org.apache.tapestry5.runtime.Component) Link(org.apache.tapestry5.Link)

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 Link (org.apache.tapestry5.Link)1 Component (org.apache.tapestry5.runtime.Component)1