Search in sources :

Example 1 with Submit

use of org.apache.tapestry5.corelib.components.Submit in project tapestry-5 by apache.

the class SubmitTest method test_imagesubmit_event_fired.

@Test
public void test_imagesubmit_event_fired() {
    Request request = mockRequest();
    final ComponentResources resources = mockComponentResources();
    FormSupport formSupport = mockFormSupport();
    Asset image = mockAsset();
    String elementName = "myname";
    train_getParameter(request, Form.SUBMITTING_ELEMENT_ID, null);
    train_getParameter(request, elementName + ".x", "15");
    formSupport.defer(isA(Runnable.class));
    replay();
    Submit submit = new Submit(request);
    TestBase.set(submit, "resources", resources, "formSupport", formSupport, "image", image);
    submit.processSubmission("xyz", elementName);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Asset(org.apache.tapestry5.Asset) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 2 with Submit

use of org.apache.tapestry5.corelib.components.Submit in project tapestry-5 by apache.

the class SubmitTest method test_submit_event_fired.

@Test
public void test_submit_event_fired() {
    Request request = mockRequest();
    final ComponentResources resources = mockComponentResources();
    FormSupport formSupport = mockFormSupport();
    String elementName = "myname";
    train_getParameter(request, Form.SUBMITTING_ELEMENT_ID, null);
    train_getParameter(request, elementName, "login");
    formSupport.defer(isA(Runnable.class));
    replay();
    Submit submit = new Submit(request);
    TestBase.set(submit, "resources", resources, "formSupport", formSupport);
    submit.processSubmission("xyz", elementName);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 3 with Submit

use of org.apache.tapestry5.corelib.components.Submit in project tapestry-5 by apache.

the class SubmitTest method submit_form.

@Test
public void submit_form() {
    Element submitButton = doc.getElementById("capitalize1");
    assertEquals("submit", submitButton.getAttribute("type"));
    fieldValues.put("t1", "hello");
    doc = tester.clickSubmit(submitButton, fieldValues);
    assertTrue(doc.toString().contains("Value is: HELLO"));
}
Also used : Element(org.apache.tapestry5.dom.Element) Test(org.testng.annotations.Test)

Example 4 with Submit

use of org.apache.tapestry5.corelib.components.Submit in project tapestry-5 by apache.

the class PageTesterTest method on_activate_chain_is_followed.

@Test(dataProvider = "testers")
public void on_activate_chain_is_followed(PageTester tester) {
    Document launchDoc = tester.renderPage("Launch");
    Map<String, String> parameters = Collections.emptyMap();
    // Submit the form, which will then skip through Intermediate and
    // arrive at Final.
    Document finalDoc = tester.submitForm(launchDoc.getElementById("form"), parameters);
    assertEquals(finalDoc.getElementById("page-name").getChildMarkup(), "Final");
}
Also used : Document(org.apache.tapestry5.dom.Document) Test(org.testng.annotations.Test)

Example 5 with Submit

use of org.apache.tapestry5.corelib.components.Submit in project tapestry-5 by apache.

the class Form method beginRender.

void beginRender(MarkupWriter writer) {
    Link link = resources.createFormEventLink(EventConstants.ACTION, context);
    String actionURL = secure && secureEnabled ? link.toAbsoluteURI(true) : link.toURI();
    actionSink = new ComponentActionSink(logger, clientDataEncoder);
    clientId = javascriptSupport.allocateClientId(resources);
    // Pre-register some names, to prevent client-side collisions with function names
    // attached to the JS Form object.
    IdAllocator allocator = new IdAllocator();
    preallocateNames(allocator);
    formSupport = createRenderTimeFormSupport(clientId, actionSink, allocator);
    environment.push(FormSupport.class, formSupport);
    environment.push(ValidationTracker.class, tracker);
    if (autofocus) {
        ValidationDecorator autofocusDecorator = new AutofocusValidationDecorator(environment.peek(ValidationDecorator.class), tracker, javascriptSupport);
        environment.push(ValidationDecorator.class, autofocusDecorator);
    }
    // Now that the environment is setup, inform the component or other
    // listeners that the form
    // is about to render.
    resources.triggerEvent(EventConstants.PREPARE_FOR_RENDER, context, null);
    resources.triggerEvent(EventConstants.PREPARE, context, null);
    // Push BeanValidationContext only after the container had a chance to prepare
    environment.push(BeanValidationContext.class, new BeanValidationContextImpl(validate));
    // Save the form element for later, in case we want to write an encoding
    // type attribute.
    form = writer.element("form", "id", clientId, "method", "post", "action", actionURL, "data-update-zone", zone, DATA_ATTRIBUTE, DATA_ATTRIBUTE_VALUE);
    if (clientValidation != ClientValidation.NONE) {
        writer.attributes("data-validate", "submit");
    }
    if (async) {
        javascriptSupport.require("t5/core/zone");
        writer.attributes("data-async-trigger", true);
    }
    resources.renderInformalParameters(writer);
    div = writer.element("div");
    for (String parameterName : link.getParameterNames()) {
        String[] values = link.getParameterValues(parameterName);
        for (String value : values) {
            // but the input value shouldn't be encoded.
            try {
                value = URLDecoder.decode(value, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logger.error("Enable to decode parameter value for parameter {} in form {}", parameterName, form.getName(), e);
            }
            writer.element("input", "type", "hidden", "name", parameterName, "value", value);
            writer.end();
        }
    }
    // div
    writer.end();
    environment.peek(Heartbeat.class).begin();
}
Also used : ComponentActionSink(org.apache.tapestry5.corelib.internal.ComponentActionSink) IdAllocator(org.apache.tapestry5.ioc.util.IdAllocator) AutofocusValidationDecorator(org.apache.tapestry5.internal.util.AutofocusValidationDecorator) Heartbeat(org.apache.tapestry5.services.Heartbeat) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AutofocusValidationDecorator(org.apache.tapestry5.internal.util.AutofocusValidationDecorator) Link(org.apache.tapestry5.http.Link) BeanValidationContextImpl(org.apache.tapestry5.internal.BeanValidationContextImpl)

Aggregations

Test (org.testng.annotations.Test)8 Request (org.apache.tapestry5.http.services.Request)5 ComponentResources (org.apache.tapestry5.ComponentResources)4 Element (org.apache.tapestry5.dom.Element)4 FormSupport (org.apache.tapestry5.services.FormSupport)4 ComponentActionSink (org.apache.tapestry5.corelib.internal.ComponentActionSink)2 Heartbeat (org.apache.tapestry5.services.Heartbeat)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Asset (org.apache.tapestry5.Asset)1 Form (org.apache.tapestry5.corelib.components.Form)1 FormSupportAdapter (org.apache.tapestry5.corelib.internal.FormSupportAdapter)1 FormSupportImpl (org.apache.tapestry5.corelib.internal.FormSupportImpl)1 HiddenFieldPositioner (org.apache.tapestry5.corelib.internal.HiddenFieldPositioner)1 Document (org.apache.tapestry5.dom.Document)1 Visitor (org.apache.tapestry5.dom.Visitor)1 Link (org.apache.tapestry5.http.Link)1 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)1 HeartbeatImpl (org.apache.tapestry5.internal.services.HeartbeatImpl)1