Search in sources :

Example 1 with PartialMarkupRenderer

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

the class RenderCommandComponentEventResultProcessor method renderMarkup.

/**
 * As a filter, this class does three things:
 * <ul>
 * <li>It creates an outer element to capture the partial page content that will be rendered</li>
 * <li>It does setup and cleanup with the {@link AjaxFormUpdateController}</li>
 * <li>It extracts the child markup and stuffs it into the reply's "content" property.</li>
 * </ul>
 */
public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
    // The partial will quite often contain multiple elements (or just a block of plain text),
    // so those must be enclosed in a root element.
    Element root = writer.element("ajax-partial");
    ajaxFormUpdateController.setupBeforePartialZoneRender(writer);
    renderer.renderMarkup(writer, reply);
    ajaxFormUpdateController.cleanupAfterPartialZoneRender();
    writer.end();
    String content = root.getChildMarkup().trim();
    reply.put("content", content);
}
Also used : Element(org.apache.tapestry5.dom.Element)

Example 2 with PartialMarkupRenderer

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

the class AjaxFormLoop method onInjectRow.

Object onInjectRow(EventContext context) {
    ComponentEventCallback callback = new ComponentEventCallback() {

        public boolean handleResult(Object result) {
            value = result;
            return true;
        }
    };
    resources.triggerContextEvent(EventConstants.ADD_ROW, context, callback);
    if (value == null)
        throw new IllegalArgumentException(String.format("Event handler for event 'addRow' from %s should have returned a non-null value.", resources.getCompleteId()));
    ajaxResponseRenderer.addFilter(new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            pushContext();
            renderer.renderMarkup(writer, reply);
            popContext();
        }
    });
    return ajaxResponse;
}
Also used : PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) JSONObject(org.apache.tapestry5.json.JSONObject) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) JSONObject(org.apache.tapestry5.json.JSONObject)

Example 3 with PartialMarkupRenderer

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

the class SingleZonePartialRendererFilter method renderMarkup.

public void renderMarkup(MarkupWriter writer, final JSONObject reply, PartialMarkupRenderer renderer) {
    RenderCommand forZone = new RenderCommand() {

        public void render(MarkupWriter writer, RenderQueue queue) {
            // Create an element to contain the content for the zone. We give it a mnemonic
            // element name and attribute just to help with debugging (the element itself is discarded).
            final Element zoneContainer = writer.element("zone-update", "zoneId", zoneId);
            ajaxFormUpdateController.setupBeforePartialZoneRender(writer);
            queue.push(new RenderCommand() {

                public void render(MarkupWriter writer, RenderQueue queue) {
                    // the zoneContainer element
                    writer.end();
                    // Need to do this Ajax Form-related cleanup here, before we extract the zone content.
                    ajaxFormUpdateController.cleanupAfterPartialZoneRender();
                    String zoneUpdateContent = zoneContainer.getChildMarkup();
                    zoneContainer.remove();
                    // This has changed a bit in 5.4;
                    // In 5.3, it was just "zones", and was key/value pairs for id and content.
                    // In 5.4, it is "content", and is an array of id/content arrays
                    reply.in(InternalConstants.PARTIAL_KEY).append("content", new JSONArray(zoneId, zoneUpdateContent));
                }
            });
            // Make sure the zone's actual rendering command is processed first, then the inline
            // RenderCommand just above.
            queue.push(zoneRenderCommand);
        }
    };
    queue.addPartialRenderer(forZone);
    renderer.renderMarkup(writer, reply);
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) Element(org.apache.tapestry5.dom.Element) JSONArray(org.apache.tapestry5.json.JSONArray) PageRenderQueue(org.apache.tapestry5.internal.services.PageRenderQueue) RenderQueue(org.apache.tapestry5.runtime.RenderQueue) MarkupWriter(org.apache.tapestry5.MarkupWriter)

Example 4 with PartialMarkupRenderer

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

the class PageRenderQueueImpl method renderPartial.

public void renderPartial(MarkupWriter writer, JSONObject reply) {
    checkQueue();
    PartialMarkupRenderer terminator = new PartialMarkupRenderer() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply) {
            render(writer);
        }
    };
    PartialMarkupRenderer delegate = terminator;
    while (!filters.isEmpty()) {
        PartialMarkupRendererFilter filter = filters.pop();
        PartialMarkupRenderer bridge = new Bridge(filter, delegate);
        delegate = bridge;
    }
    // The initialize methods will already have been invoked.
    delegate.renderMarkup(writer, reply);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) MarkupWriter(org.apache.tapestry5.MarkupWriter)

Example 5 with PartialMarkupRenderer

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

the class TapestryModule method contributePartialMarkupRenderer.

/**
 * Contributes {@link PartialMarkupRendererFilter}s used when rendering a
 * partial Ajax response.
 * <dl>
 * <dt>DocumentLinker
 * <dd>Provides {@link org.apache.tapestry5.internal.services.DocumentLinker}
 * <dt>ClientBehaviorSupport</dt>
 * <dd>Provides {@link ClientBehaviorSupport}</dd>
 * <dt>Heartbeat</dt>
 * <dd>Provides {@link org.apache.tapestry5.services.Heartbeat}</dd>
 * <dt>DefaultValidationDecorator</dt>
 * <dt>ValidationDecorator</dt>
 * <dd>Provides {@link org.apache.tapestry5.ValidationDecorator} (via {@link ValidationDecoratorFactory#newInstance(org.apache.tapestry5.MarkupWriter)})</dd>
 * </dl>
 */
public void contributePartialMarkupRenderer(OrderedConfiguration<PartialMarkupRendererFilter> configuration, final ValidationDecoratorFactory validationDecoratorFactory) {
    PartialMarkupRendererFilter documentLinker = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            PartialMarkupDocumentLinker linker = new PartialMarkupDocumentLinker();
            environment.push(DocumentLinker.class, linker);
            renderer.renderMarkup(writer, reply);
            environment.pop(DocumentLinker.class);
            linker.commit(reply);
        }
    };
    PartialMarkupRendererFilter clientBehaviorSupport = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            ClientBehaviorSupportImpl support = new ClientBehaviorSupportImpl();
            environment.push(ClientBehaviorSupport.class, support);
            renderer.renderMarkup(writer, reply);
            environment.pop(ClientBehaviorSupport.class);
        }
    };
    PartialMarkupRendererFilter heartbeat = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            Heartbeat heartbeat = new HeartbeatImpl();
            heartbeat.begin();
            environment.push(Heartbeat.class, heartbeat);
            renderer.renderMarkup(writer, reply);
            environment.pop(Heartbeat.class);
            heartbeat.end();
        }
    };
    PartialMarkupRendererFilter defaultValidationDecorator = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            ValidationDecorator decorator = validationDecoratorFactory.newInstance(writer);
            environment.push(ValidationDecorator.class, decorator);
            renderer.renderMarkup(writer, reply);
            environment.pop(ValidationDecorator.class);
        }
    };
    configuration.add("DocumentLinker", documentLinker);
    configuration.add("ClientBehaviorSupport", clientBehaviorSupport, "after:JavaScriptSupport");
    configuration.add("Heartbeat", heartbeat);
    configuration.add("ValidationDecorator", defaultValidationDecorator);
}
Also used : PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) JSONObject(org.apache.tapestry5.json.JSONObject) Heartbeat(org.apache.tapestry5.services.Heartbeat) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) MarkupWriter(org.apache.tapestry5.MarkupWriter) ValidationDecorator(org.apache.tapestry5.ValidationDecorator)

Aggregations

MarkupWriter (org.apache.tapestry5.MarkupWriter)4 JSONObject (org.apache.tapestry5.json.JSONObject)4 PartialMarkupRenderer (org.apache.tapestry5.services.PartialMarkupRenderer)4 PartialMarkupRendererFilter (org.apache.tapestry5.services.PartialMarkupRendererFilter)4 Element (org.apache.tapestry5.dom.Element)2 BooleanHook (org.apache.tapestry5.BooleanHook)1 ValidationDecorator (org.apache.tapestry5.ValidationDecorator)1 DocumentLinker (org.apache.tapestry5.internal.services.DocumentLinker)1 PageRenderQueue (org.apache.tapestry5.internal.services.PageRenderQueue)1 JavaScriptSupportImpl (org.apache.tapestry5.internal.services.ajax.JavaScriptSupportImpl)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 IdAllocator (org.apache.tapestry5.ioc.util.IdAllocator)1 JSONArray (org.apache.tapestry5.json.JSONArray)1 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)1 RenderQueue (org.apache.tapestry5.runtime.RenderQueue)1 Heartbeat (org.apache.tapestry5.services.Heartbeat)1