Search in sources :

Example 96 with Value

use of org.apache.tapestry5.ioc.annotations.Value 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 97 with Value

use of org.apache.tapestry5.ioc.annotations.Value 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 98 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project spock by spockframework.

the class TapestryInterceptor method injectServices.

private void injectServices(Object target, boolean sharedFields) throws IllegalAccessException {
    for (final FieldInfo field : spec.getAllFields()) {
        Field rawField = field.getReflection();
        if ((rawField.isAnnotationPresent(Inject.class) || ReflectionUtil.isAnnotationPresent(rawField, "javax.inject.Inject") || rawField.isAnnotationPresent(Autobuild.class)) && rawField.isAnnotationPresent(Shared.class) == sharedFields) {
            Object value = registry.getObject(rawField.getType(), createAnnotationProvider(field));
            rawField.setAccessible(true);
            rawField.set(target, value);
        } else if (rawField.isAnnotationPresent(InjectService.class)) {
            String serviceName = rawField.getAnnotation(InjectService.class).value();
            Object value = registry.getService(serviceName, rawField.getType());
            rawField.setAccessible(true);
            rawField.set(target, value);
        }
    }
}
Also used : Field(java.lang.reflect.Field) Autobuild(org.apache.tapestry5.ioc.annotations.Autobuild) InjectService(org.apache.tapestry5.ioc.annotations.InjectService) FieldInfo(org.spockframework.runtime.model.FieldInfo)

Example 99 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class AjaxComponentEventRequestHandler method handle.

public void handle(ComponentEventRequestParameters parameters) throws IOException {
    Page activePage = cache.get(parameters.getActivePageName());
    final Holder<Boolean> resultProcessorInvoked = Holder.create();
    resultProcessorInvoked.put(false);
    ComponentEventResultProcessor interceptor = new ComponentEventResultProcessor() {

        public void processResultValue(Object value) throws IOException {
            resultProcessorInvoked.put(true);
            resultProcessor.processResultValue(value);
        }
    };
    // If we end up doing a partial render, the page render queue service needs to know the
    // page that will be rendered (for logging purposes, if nothing else).
    queue.setRenderingPage(activePage);
    request.setAttribute(InternalConstants.PAGE_NAME_ATTRIBUTE_NAME, parameters.getActivePageName());
    if (pageActivator.activatePage(activePage.getRootElement().getComponentResources(), parameters.getPageActivationContext(), interceptor))
        return;
    Page containerPage = cache.get(parameters.getContainingPageName());
    ComponentPageElement element = containerPage.getComponentElementByNestedId(parameters.getNestedComponentId());
    // In many cases, the triggered element is a Form that needs to be able to
    // pass its event handler return values to the correct result processor.
    // This is certainly the case for forms.
    TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(interceptor);
    environment.push(ComponentEventResultProcessor.class, interceptor);
    environment.push(TrackableComponentEventCallback.class, callback);
    boolean handled = element.triggerContextEvent(parameters.getEventType(), parameters.getEventContext(), callback);
    if (!handled)
        throw new TapestryException(String.format("Request event '%s' (on component %s) was not handled; you must provide a matching event handler method in the component or in one of its containers.", parameters.getEventType(), element.getCompleteId()), element, null);
    environment.pop(TrackableComponentEventCallback.class);
    environment.pop(ComponentEventResultProcessor.class);
    // If the result processor was passed a value, then it will already have rendered. Otherwise it was not passed a value,
    // but it's still possible that we still want to do a partial page render ... if filters were added to the render queue.
    // In that event, run the partial page render now and return.
    boolean wasInvoked = resultProcessorInvoked.get();
    if ((!wasInvoked) && queue.isPartialRenderInitialized()) {
        partialRenderer.renderPartialPageMarkup();
        return;
    }
    if (wasInvoked) {
        return;
    }
    // Send an empty JSON reply if no value was returned from the component event handler method.
    // This is the typical behavior when an Ajax component event handler returns null. It still
    // will go through a pipeline that will add information related to partial page rendering.
    resultProcessor.processResultValue(new JSONObject());
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentEventResultProcessor(org.apache.tapestry5.services.ComponentEventResultProcessor) JSONObject(org.apache.tapestry5.json.JSONObject) TrackableComponentEventCallback(org.apache.tapestry5.TrackableComponentEventCallback) Page(org.apache.tapestry5.internal.structure.Page) JSONObject(org.apache.tapestry5.json.JSONObject) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 100 with Value

use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.

the class AjaxLinkComponentEventResultProcessor method processResultValue.

public void processResultValue(Link value) throws IOException {
    JSONObject response = new JSONObject();
    response.in(InternalConstants.PARTIAL_KEY).put("redirectURL", value.toRedirectURI());
    masterProcessor.processResultValue(response);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject)

Aggregations

Test (org.testng.annotations.Test)83 ComponentResources (org.apache.tapestry5.ComponentResources)30 ComponentModel (org.apache.tapestry5.model.ComponentModel)16 MarkupWriter (org.apache.tapestry5.MarkupWriter)13 Field (org.apache.tapestry5.Field)12 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)11 Location (org.apache.tapestry5.commons.Location)11 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)11 Type (org.apache.tapestry5.internal.plastic.asm.Type)11 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)11 Messages (org.apache.tapestry5.commons.Messages)10 JSONObject (org.apache.tapestry5.json.JSONObject)10 Request (org.apache.tapestry5.http.services.Request)9 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)8 Link (org.apache.tapestry5.http.Link)8 Binding (org.apache.tapestry5.Binding)7 ValidationException (org.apache.tapestry5.ValidationException)7 InternalPropertyConduit (org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)7