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();
}
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);
}
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));
}
}
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();
}
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\"/>");
}
Aggregations