Search in sources :

Example 1 with FormSupportImpl

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();
}
Also used : Field(org.apache.tapestry5.Field) ClientBehaviorSupport(org.apache.tapestry5.services.ClientBehaviorSupport) Test(org.testng.annotations.Test)

Example 2 with FormSupportImpl

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);
        }
    }
}
Also used : Heartbeat(org.apache.tapestry5.services.Heartbeat) FormSupportImpl(org.apache.tapestry5.corelib.internal.FormSupportImpl) HeartbeatImpl(org.apache.tapestry5.internal.services.HeartbeatImpl) BeanValidationContextImpl(org.apache.tapestry5.internal.BeanValidationContextImpl)

Example 3 with FormSupportImpl

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();
}
Also used : Request(org.apache.tapestry5.http.services.Request) FormSupportImpl(org.apache.tapestry5.corelib.internal.FormSupportImpl) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Aggregations

FormSupportImpl (org.apache.tapestry5.corelib.internal.FormSupportImpl)2 Test (org.testng.annotations.Test)2 ComponentResources (org.apache.tapestry5.ComponentResources)1 Field (org.apache.tapestry5.Field)1 Request (org.apache.tapestry5.http.services.Request)1 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)1 HeartbeatImpl (org.apache.tapestry5.internal.services.HeartbeatImpl)1 ClientBehaviorSupport (org.apache.tapestry5.services.ClientBehaviorSupport)1 Heartbeat (org.apache.tapestry5.services.Heartbeat)1