use of org.apache.tapestry5.corelib.internal.FormSupportImpl in project tapestry-5 by apache.
the class FormSupportImplTest method add_validation_when_client_validation_is_disabled.
@Test
public void add_validation_when_client_validation_is_disabled() {
Field barney = mockField();
ClientBehaviorSupport clientBehaviorSupport = mockClientBehaviorSupport();
replay();
FormSupportImpl support = new FormSupportImpl(null, null, null, false, null, null);
support.addValidation(barney, "required", "Who can live without Barney?", null);
verify();
}
use of org.apache.tapestry5.corelib.internal.FormSupportImpl 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.corelib.internal.FormSupportImpl in project tapestry-5 by apache.
the class SubmitTest method trigger_deferred.
@Test
public void trigger_deferred() {
Request request = mockRequest();
ComponentResources resources = mockComponentResources();
FormSupportImpl support = new FormSupportImpl(null, null);
String elementName = "myname";
// Also: test for the alternate, JavaScript oriented way, of determining the
// element/component that triggered the submission.
train_getParameter(request, Form.SUBMITTING_ELEMENT_ID, "[ 'xyz', 'pdq' ]");
replay();
Submit submit = new Submit(request);
TestBase.set(submit, "resources", resources, "formSupport", support);
submit.processSubmission("xyz", elementName);
verify();
expect(resources.triggerEvent(EventConstants.SELECTED, null, null)).andReturn(false);
replay();
support.executeDeferred();
verify();
}
Aggregations