Search in sources :

Example 1 with Zone

use of org.apache.tapestry5.corelib.components.Zone 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)

Example 2 with Zone

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

the class GridPager method writePageLink.

private void writePageLink(MarkupWriter writer, int pageIndex) {
    if (pageIndex < 1 || pageIndex > maxPages)
        return;
    if (pageIndex <= lastIndex)
        return;
    final boolean isBootstrap4 = isBootstrap4();
    if (pageIndex != lastIndex + 1) {
        writer.element("li", "class", isBootstrap4 ? "disabled page-item" : "disabled");
        writer.element("a", "href", "#", "aria-disabled", "true");
        addClassAttributeToPageLinkIfNeeded(writer, isBootstrap4);
        writer.write(" ... ");
        writer.end();
        writer.end();
    }
    lastIndex = pageIndex;
    if (pageIndex == currentPage) {
        writer.element("li", "aria-current", "page", "class", isBootstrap4 ? "active page-item" : "active");
        writer.element("a", "href", "#", "aria-disabled", "true");
        addClassAttributeToPageLinkIfNeeded(writer, isBootstrap4);
        writer.write(Integer.toString(pageIndex));
        writer.end();
        writer.end();
        return;
    }
    writer.element("li");
    if (isBootstrap4) {
        writer.getElement().attribute("class", "page-item");
    }
    Link link = resources.createEventLink(EventConstants.ACTION, pageIndex);
    if (zone != null) {
        link.addParameter("t:inplace", "true");
    }
    writer.element("a", "href", link, "data-update-zone", zone, "title", messages.format("core-goto-page", pageIndex));
    addClassAttributeToPageLinkIfNeeded(writer, isBootstrap4);
    writer.write(Integer.toString(pageIndex));
    writer.end();
    // li
    writer.end();
}
Also used : Link(org.apache.tapestry5.http.Link)

Example 3 with Zone

use of org.apache.tapestry5.corelib.components.Zone in project tapestry5-hotel-booking by ccordenier.

the class AjaxLoader method initAjaxLoader.

@BeginRender
void initAjaxLoader(MarkupWriter writer) {
    loader = javascriptSupport.allocateClientId("loader");
    JSONObject data = new JSONObject();
    data.put("zone", zone);
    data.put("trigger", trigger);
    data.put("loader", loader);
    javascriptSupport.addInitializerCall(InitializationPriority.NORMAL, "initAjaxLoader", data);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) BeginRender(org.apache.tapestry5.annotations.BeginRender)

Example 4 with Zone

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

the class ZoneRefresh method addJavaScript.

@AfterRender
void addJavaScript() {
    Link link = resources.createEventLink("zoneRefresh", context);
    javaScriptSupport.require("t5/core/zone-refresh").with(zone.getClientId(), period, link.toString());
}
Also used : Link(org.apache.tapestry5.http.Link) AfterRender(org.apache.tapestry5.annotations.AfterRender)

Example 5 with Zone

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

the class MultiZoneUpdateEventResultProcessor method processResultValue.

public void processResultValue(final MultiZoneUpdate value) throws IOException {
    Map<String, Object> map = value.getZoneToRenderMap();
    for (String zoneId : map.keySet()) {
        Object provided = map.get(zoneId);
        // The AjaxResponseRenderer will convert the object to a RenderCommand, but does nothing special if there's a failure
        // (because the stack trace will clearly identify what's going on). We do the conversion here so that we can relate
        // a failure to a zone id. It will just be a pass-thru on the second type coercion.
        RenderCommand zoneRenderCommand = toRenderer(zoneId, provided);
        ajaxResponseRenderer.addRender(zoneId, zoneRenderCommand);
    }
    // This is actually executed deferred:
    partialRenderer.renderPartialPageMarkup();
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand)

Aggregations

Link (org.apache.tapestry5.http.Link)6 ComponentActionSink (org.apache.tapestry5.corelib.internal.ComponentActionSink)2 Element (org.apache.tapestry5.dom.Element)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 MultiZoneUpdate (org.apache.tapestry5.ajax.MultiZoneUpdate)1 AfterRender (org.apache.tapestry5.annotations.AfterRender)1 BeginRender (org.apache.tapestry5.annotations.BeginRender)1 FormSupportAdapter (org.apache.tapestry5.corelib.internal.FormSupportAdapter)1 HiddenFieldPositioner (org.apache.tapestry5.corelib.internal.HiddenFieldPositioner)1 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)1 PageRenderQueue (org.apache.tapestry5.internal.services.PageRenderQueue)1 AutofocusValidationDecorator (org.apache.tapestry5.internal.util.AutofocusValidationDecorator)1 IdAllocator (org.apache.tapestry5.ioc.util.IdAllocator)1 JSONArray (org.apache.tapestry5.json.JSONArray)1 RenderQueue (org.apache.tapestry5.runtime.RenderQueue)1 Heartbeat (org.apache.tapestry5.services.Heartbeat)1 JavaScriptCallback (org.apache.tapestry5.services.ajax.JavaScriptCallback)1