Search in sources :

Example 1 with JavaScriptSupport

use of org.apache.tapestry5.services.javascript.JavaScriptSupport in project flowlogix by flowlogix.

the class DisableAfterSubmit method enableSubmitProcessing.

public static void enableSubmitProcessing(ClientElement clientElement, FormSupport fs, JavaScriptSupport js) {
    JSONObject spec = new JSONObject();
    spec.put("elementId", clientElement.getClientId());
    spec.put("formId", fs.getClientId());
    js.addInitializerCall("disableAfterSubmit", spec);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject)

Example 2 with JavaScriptSupport

use of org.apache.tapestry5.services.javascript.JavaScriptSupport in project tapestry-5 by apache.

the class AnyTest method render_simple.

@Test
public void render_simple() {
    ComponentResources resources = mockComponentResources();
    JavaScriptSupport support = mockJavaScriptSupport();
    MarkupWriter writer = new MarkupWriterImpl(new DefaultMarkupModel());
    resources.renderInformalParameters(writer);
    replay();
    Any component = new Any();
    component.inject(support, resources, "span", "foo");
    component.beginRender(writer);
    writer.write("content");
    component.afterRender(writer);
    assertEquals(writer.toString(), "<span>content</span>");
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) DefaultMarkupModel(org.apache.tapestry5.dom.DefaultMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 3 with JavaScriptSupport

use of org.apache.tapestry5.services.javascript.JavaScriptSupport in project tapestry-5 by apache.

the class AnyTest method render_with_id.

@Test
public void render_with_id() {
    ComponentResources resources = mockComponentResources();
    JavaScriptSupport support = mockJavaScriptSupport();
    MarkupWriter writer = new MarkupWriterImpl(new DefaultMarkupModel());
    resources.renderInformalParameters(writer);
    String clientId = "bar";
    String uniqueId = "bar_0";
    expect(support.allocateClientId(clientId)).andReturn(uniqueId);
    replay();
    Any component = new Any();
    component.inject(support, resources, "div", clientId);
    component.beginRender(writer);
    writer.write("content");
    component.afterRender(writer);
    assertEquals(writer.toString(), "<div>content</div>");
    assertEquals(component.getClientId(), uniqueId);
    assertEquals(writer.toString(), "<div id=\"bar_0\">content</div>");
    assertEquals(component.getClientId(), uniqueId);
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) DefaultMarkupModel(org.apache.tapestry5.dom.DefaultMarkupModel) MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 4 with JavaScriptSupport

use of org.apache.tapestry5.services.javascript.JavaScriptSupport in project tapestry-5 by apache.

the class AnyTest method attempt_to_get_client_id_before_render.

@Test
public void attempt_to_get_client_id_before_render() {
    ComponentResources resources = mockComponentResources();
    JavaScriptSupport support = mockJavaScriptSupport();
    train_getCompleteId(resources, "Foo/bar.baz");
    replay();
    Any component = new Any();
    component.inject(support, resources, "div", null);
    try {
        component.getClientId();
        unreachable();
    } catch (IllegalStateException ex) {
        assertEquals(ex.getMessage(), "Unable to provide client id for component Foo/bar.baz as it has not yet rendered.");
    }
    verify();
}
Also used : JavaScriptSupport(org.apache.tapestry5.services.javascript.JavaScriptSupport) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 5 with JavaScriptSupport

use of org.apache.tapestry5.services.javascript.JavaScriptSupport 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

JavaScriptSupport (org.apache.tapestry5.services.javascript.JavaScriptSupport)7 MarkupWriter (org.apache.tapestry5.MarkupWriter)4 Test (org.testng.annotations.Test)4 ComponentResources (org.apache.tapestry5.ComponentResources)3 JavaScriptCallback (org.apache.tapestry5.services.ajax.JavaScriptCallback)3 BooleanHook (org.apache.tapestry5.BooleanHook)2 DefaultMarkupModel (org.apache.tapestry5.dom.DefaultMarkupModel)2 DocumentLinker (org.apache.tapestry5.internal.services.DocumentLinker)2 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)2 JavaScriptSupportImpl (org.apache.tapestry5.internal.services.ajax.JavaScriptSupportImpl)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 IdAllocator (org.apache.tapestry5.ioc.util.IdAllocator)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 PartialMarkupRenderer (org.apache.tapestry5.services.PartialMarkupRenderer)2 PartialMarkupRendererFilter (org.apache.tapestry5.services.PartialMarkupRendererFilter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MultiZoneUpdate (org.apache.tapestry5.ajax.MultiZoneUpdate)1 PlasticProxyFactory (org.apache.tapestry5.commons.services.PlasticProxyFactory)1 ComponentActionSink (org.apache.tapestry5.corelib.internal.ComponentActionSink)1 Link (org.apache.tapestry5.http.Link)1