use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class UploadTest method begin_render_invokes_field_validator.
@SuppressWarnings("unchecked")
@Test
public void begin_render_invokes_field_validator() throws Exception {
getMocksControl().checkOrder(true);
FieldValidator<Object> validate = mockFieldValidator();
ComponentResources resources = mockComponentResources();
Upload component = new Upload(null, validate, null, null, resources, null);
MarkupWriter writer = createMarkupWriter();
writer.element("form");
Request request = mockRequest();
FormSupport formSupport = mockFormSupport();
formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
ValidationDecorator decorator = mockValidationDecorator();
component.injectDecorator(decorator).injectRequest(request).injectFormSupport(formSupport);
validate.render(writer);
resources.renderInformalParameters(writer);
decorator.insideField(component);
train_isXHR(request, false);
replay();
component.beginRender(writer);
verify();
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class UploadTest method process_submission_calls_validator.
@SuppressWarnings("unchecked")
@Test
public void process_submission_calls_validator() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
FieldValidator<Object> validate = mockFieldValidator();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
Upload component = new Upload(null, validate, decoder, null, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
support.validate(uploadedFile, resources, validate);
replay();
component.processSubmission("test");
verify();
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class Upload method processSubmission.
@SuppressWarnings({ "unchecked" })
@Override
protected void processSubmission(String controlName) {
UploadedFile uploaded = decoder.getFileUpload(controlName);
if (uploaded != null && (uploaded.getFileName() == null || uploaded.getFileName().length() == 0)) {
uploaded = null;
}
try {
fieldValidationSupport.validate(uploaded, resources, validate);
} catch (ValidationException ex) {
validationTracker.recordError(this, ex.getMessage());
}
value = uploaded;
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class Form method onAction.
@SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
Object onAction(EventContext context) throws IOException {
beforeProcessSubmit(context);
tracker.clear();
formSupport = new FormSupportImpl(resources, validationId);
environment.push(ValidationTracker.class, tracker);
environment.push(FormSupport.class, formSupport);
Heartbeat heartbeat = new HeartbeatImpl();
environment.push(Heartbeat.class, heartbeat);
heartbeat.begin();
boolean didPushBeanValidationContext = false;
try {
resources.triggerContextEvent(EventConstants.PREPARE_FOR_SUBMIT, context, eventCallback);
if (eventCallback.isAborted())
return true;
resources.triggerContextEvent(EventConstants.PREPARE, context, eventCallback);
if (eventCallback.isAborted())
return true;
if (isFormCancelled()) {
executeStoredActions(true);
resources.triggerContextEvent(EventConstants.CANCELED, context, eventCallback);
if (eventCallback.isAborted())
return true;
}
environment.push(BeanValidationContext.class, new BeanValidationContextImpl(validate));
didPushBeanValidationContext = true;
executeStoredActions(false);
heartbeat.end();
formSupport.executeDeferred();
fireValidateEvent(EventConstants.VALIDATE, context, eventCallback);
if (eventCallback.isAborted()) {
return true;
}
afterValidate();
if (!tracker.getHasErrors()) {
tracker.clear();
}
String eventType = tracker.getHasErrors() ? EventConstants.FAILURE : EventConstants.SUCCESS;
resources.triggerContextEvent(eventType, context, eventCallback);
if (eventCallback.isAborted()) {
return true;
}
// Lastly, tell anyone whose interested that the form is completely
// submitted.
resources.triggerContextEvent(EventConstants.SUBMIT, context, eventCallback);
afterSuccessOrFailure();
if (eventCallback.isAborted()) {
return true;
}
if (tracker.getHasErrors() && !request.isXHR()) {
return STREAM_ACTIVE_PAGE_CONTENT;
}
return false;
} finally {
environment.pop(Heartbeat.class);
environment.pop(FormSupport.class);
environment.pop(ValidationTracker.class);
if (didPushBeanValidationContext) {
environment.pop(BeanValidationContext.class);
}
}
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class Html5DateField method processSubmission.
@Override
protected void processSubmission(String controlName) {
String value = request.getParameter(controlName);
validationTracker.recordInput(this, value);
Date parsedValue = null;
try {
if (InternalUtils.isNonBlank(value))
parsedValue = getDateFormat().parse(value);
} catch (ParseException ex) {
validationTracker.recordError(this, messages.format("core-date-value-not-parseable", value));
return;
}
putPropertyNameIntoBeanValidationContext("value");
try {
fieldValidationSupport.validate(parsedValue, resources, validate);
this.value = parsedValue;
} catch (ValidationException ex) {
validationTracker.recordError(this, ex.getMessage());
}
removePropertyNameFromBeanValidationContext();
}
Aggregations