Search in sources :

Example 1 with HiddenFieldPositioner

use of org.apache.tapestry5.corelib.internal.HiddenFieldPositioner in project tapestry-5 by apache.

the class AjaxFormUpdateControllerImpl method setupBeforePartialZoneRender.

public void setupBeforePartialZoneRender(MarkupWriter writer) {
    if (formComponentId == null)
        return;
    hiddenFieldPositioner = new HiddenFieldPositioner(writer, rules);
    actionSink = new ComponentActionSink(logger, clientDataEncoder);
    formSupport = createInternalFormSupport(formClientId, formComponentId, actionSink);
    environment.push(FormSupport.class, formSupport);
    environment.push(ValidationTracker.class, new ValidationTrackerImpl());
    heartbeat.begin();
}
Also used : ComponentActionSink(org.apache.tapestry5.corelib.internal.ComponentActionSink) HiddenFieldPositioner(org.apache.tapestry5.corelib.internal.HiddenFieldPositioner) ValidationTrackerImpl(org.apache.tapestry5.ValidationTrackerImpl)

Example 2 with HiddenFieldPositioner

use of org.apache.tapestry5.corelib.internal.HiddenFieldPositioner in project tapestry-5 by apache.

the class FormFragment method beginRender.

/**
 * Renders a <div> tag and provides an override of the {@link org.apache.tapestry5.services.FormSupport}
 * environmental.
 */
void beginRender(MarkupWriter writer) {
    FormSupport formSupport = environment.peekRequired(FormSupport.class);
    String clientId = getClientId();
    hiddenFieldPositioner = new HiddenFieldPositioner(writer, rules);
    Element element = writer.element(this.element, "id", clientId, "data-component-type", "core/FormFragment");
    if (alwaysSubmit) {
        element.attribute("data-always-submit", "true");
    }
    resources.renderInformalParameters(writer);
    if (!visible) {
        element.attribute("style", "display: none;");
        if (!alwaysSubmit) {
            javascriptSupport.require("t5/core/form-fragment").invoke("hide").with(clientId);
        }
    }
    componentActions = new ComponentActionSink(logger, clientDataEncoder);
    // Here's the magic of environmentals ... we can create a wrapper around
    // the normal FormSupport environmental that intercepts some of the behavior.
    // Here we're setting aside all the actions inside the FormFragment so that we
    // can control whether those actions occur when the form is submitted.
    FormSupport override = new FormSupportAdapter(formSupport) {

        @Override
        public <T> void store(T component, ComponentAction<T> action) {
            componentActions.store(component, action);
        }

        @Override
        public <T> void storeCancel(T component, ComponentAction<T> action) {
            componentActions.storeCancel(component, action);
        }

        @Override
        public <T> void storeAndExecute(T component, ComponentAction<T> action) {
            componentActions.store(component, action);
            action.execute(component);
        }
    };
    // Tada! Now all the enclosed components will use our override of FormSupport,
    // until we pop it off.
    environment.push(FormSupport.class, override);
}
Also used : ComponentActionSink(org.apache.tapestry5.corelib.internal.ComponentActionSink) HiddenFieldPositioner(org.apache.tapestry5.corelib.internal.HiddenFieldPositioner) Element(org.apache.tapestry5.dom.Element) FormSupportAdapter(org.apache.tapestry5.corelib.internal.FormSupportAdapter) FormSupport(org.apache.tapestry5.services.FormSupport)

Example 3 with HiddenFieldPositioner

use of org.apache.tapestry5.corelib.internal.HiddenFieldPositioner in project tapestry-5 by apache.

the class Zone method beginRender.

void beginRender(MarkupWriter writer) {
    clientId = resources.isBound("id") ? idParameter : javascriptSupport.allocateClientId(resources);
    Element e = writer.element(elementName, "id", clientId, "data-container-type", "zone");
    if (simpleIds) {
        e.attribute("data-simple-ids", "true");
    }
    resources.renderInformalParameters(writer);
    insideForm = formSupport != null;
    if (insideForm) {
        JSONObject parameters = new JSONObject(RequestConstants.FORM_CLIENTID_PARAMETER, formSupport.getClientId(), RequestConstants.FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId());
        e.attribute("data-zone-parameters", parameters.toString(compactJSON));
        hiddenFieldPositioner = new HiddenFieldPositioner(writer, rules);
        actionSink = new ComponentActionSink(logger, clientDataEncoder);
        environment.push(FormSupport.class, new FormSupportAdapter(formSupport) {

            @Override
            public <T> void store(T component, ComponentAction<T> action) {
                actionSink.store(component, action);
            }

            @Override
            public <T> void storeCancel(T component, ComponentAction<T> action) {
                actionSink.storeCancel(component, action);
            }

            @Override
            public <T> void storeAndExecute(T component, ComponentAction<T> action) {
                store(component, action);
                action.execute(component);
            }
        });
    }
    heartbeat.begin();
}
Also used : ComponentActionSink(org.apache.tapestry5.corelib.internal.ComponentActionSink) HiddenFieldPositioner(org.apache.tapestry5.corelib.internal.HiddenFieldPositioner) JSONObject(org.apache.tapestry5.json.JSONObject) Element(org.apache.tapestry5.dom.Element) FormSupportAdapter(org.apache.tapestry5.corelib.internal.FormSupportAdapter)

Aggregations

ComponentActionSink (org.apache.tapestry5.corelib.internal.ComponentActionSink)3 HiddenFieldPositioner (org.apache.tapestry5.corelib.internal.HiddenFieldPositioner)3 FormSupportAdapter (org.apache.tapestry5.corelib.internal.FormSupportAdapter)2 Element (org.apache.tapestry5.dom.Element)2 ValidationTrackerImpl (org.apache.tapestry5.ValidationTrackerImpl)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 FormSupport (org.apache.tapestry5.services.FormSupport)1