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);
}
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;
}
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);
}
}
}
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());
}
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);
}
Aggregations