Search in sources :

Example 11 with RenderCommand

use of org.apache.tapestry5.runtime.RenderCommand 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)

Example 12 with RenderCommand

use of org.apache.tapestry5.runtime.RenderCommand 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 13 with RenderCommand

use of org.apache.tapestry5.runtime.RenderCommand in project tapestry-5 by apache.

the class RenderQueueImpl method run.

public void run(MarkupWriter writer) {
    RenderCommand command = null;
    boolean traceEnabled = logger.isTraceEnabled(TapestryMarkers.RENDER_COMMANDS);
    boolean debugEnabled = logger.isDebugEnabled();
    long startNanos = -1l;
    if (debugEnabled) {
        startNanos = System.nanoTime();
    }
    int commandCount = 0;
    int maxDepth = 0;
    try {
        while (!queue.isEmpty()) {
            maxDepth = Math.max(maxDepth, queue.getDepth());
            command = queue.pop();
            commandCount++;
            if (traceEnabled)
                logger.trace(TapestryMarkers.RENDER_COMMANDS, "Executing: {}", command);
            command.render(writer, this);
        }
    } catch (RuntimeException ex) {
        String message = String.format("Render queue error in %s: %s", command, ExceptionUtils.toMessage(ex));
        logger.error(message, ex);
        throw new RenderQueueException(message, renderingComponents.getSnapshot(), ex);
    }
    if (debugEnabled) {
        long endNanos = System.nanoTime();
        long elapsedNanos = endNanos - startNanos;
        double elapsedSeconds = ((double) elapsedNanos) / 1000000000d;
        logger.debug(TapestryMarkers.RENDER_COMMANDS, String.format("Executed %,d rendering commands (max queue depth: %,d) in %.3f seconds", commandCount, maxDepth, elapsedSeconds));
    }
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand)

Example 14 with RenderCommand

use of org.apache.tapestry5.runtime.RenderCommand in project tapestry-5 by apache.

the class PartialTemplateRendererImpl method renderAsDocument.

public Document renderAsDocument(Object object) {
    RenderCommand renderCommand = toRenderCommand(object);
    MarkupWriter markupWriter = new MarkupWriterImpl();
    RenderQueueImpl renderQueue = new RenderQueueImpl(LOGGER);
    renderQueue.push(renderCommand);
    renderQueue.run(markupWriter);
    return markupWriter.getDocument();
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) MarkupWriter(org.apache.tapestry5.MarkupWriter)

Example 15 with RenderCommand

use of org.apache.tapestry5.runtime.RenderCommand in project tapestry-5 by apache.

the class PageElementFactoryImplTest method attribute.

@Test
public void attribute() {
    TypeCoercer typeCoercer = mockTypeCoercer();
    BindingSource bindingSource = mockBindingSource();
    MarkupWriter writer = new MarkupWriterImpl(xmlModel);
    Location l = mockLocation();
    RenderQueue queue = mockRenderQueue();
    replay();
    PageElementFactory factory = new PageElementFactoryImpl(typeCoercer, bindingSource);
    AttributeToken token = new AttributeToken(null, "name", "value", l);
    RenderCommand element = factory.newAttributeElement(null, token);
    writer.element("root");
    element.render(writer, queue);
    verify();
    assertEquals(writer.toString(), "<?xml version=\"1.0\"?>\n<root name=\"value\"/>");
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) BindingSource(org.apache.tapestry5.services.BindingSource) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) RenderQueue(org.apache.tapestry5.runtime.RenderQueue) AttributeToken(org.apache.tapestry5.internal.parser.AttributeToken) MarkupWriter(org.apache.tapestry5.MarkupWriter) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Aggregations

RenderCommand (org.apache.tapestry5.runtime.RenderCommand)18 MarkupWriter (org.apache.tapestry5.MarkupWriter)13 RenderQueue (org.apache.tapestry5.runtime.RenderQueue)13 Test (org.testng.annotations.Test)7 ComponentResources (org.apache.tapestry5.ComponentResources)3 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)3 Binding (org.apache.tapestry5.Binding)2 Block (org.apache.tapestry5.Block)2 Renderable (org.apache.tapestry5.Renderable)2 Element (org.apache.tapestry5.dom.Element)2 Logger (org.slf4j.Logger)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 Asset (org.apache.tapestry5.Asset)1