use of org.apache.tapestry5.services.PartialMarkupRendererFilter 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;
}
use of org.apache.tapestry5.services.PartialMarkupRendererFilter 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);
}
use of org.apache.tapestry5.services.PartialMarkupRendererFilter 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);
}
use of org.apache.tapestry5.services.PartialMarkupRendererFilter in project tapestry-5 by apache.
the class JavaScriptModule method exposeJavaScriptSupportForPartialPageRender.
/**
* Contributes {@link PartialMarkupRendererFilter}s used when rendering a
* partial Ajax response.
* <dl>
* <dt>JavaScriptSupport
* <dd>Provides {@link JavaScriptSupport}</dd>
* </dl>
*/
@Contribute(PartialMarkupRenderer.class)
public void exposeJavaScriptSupportForPartialPageRender(OrderedConfiguration<PartialMarkupRendererFilter> configuration, final JavaScriptStackSource javascriptStackSource, final JavaScriptStackPathConstructor javascriptStackPathConstructor, final Request request) {
final BooleanHook suppressCoreStylesheetsHook = createSuppressCoreStylesheetHook(request);
PartialMarkupRendererFilter javascriptSupport = new PartialMarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
IdAllocator idAllocator;
if (request.getParameter(InternalConstants.SUPPRESS_NAMESPACED_IDS) == null) {
String uid = Long.toHexString(System.nanoTime());
String namespace = "_" + uid;
idAllocator = new IdAllocator(namespace);
} else {
// When suppressed, work just like normal rendering.
idAllocator = new IdAllocator();
}
DocumentLinker linker = environment.peekRequired(DocumentLinker.class);
JavaScriptSupportImpl support = new JavaScriptSupportImpl(linker, javascriptStackSource, javascriptStackPathConstructor, idAllocator, true, suppressCoreStylesheetsHook);
environment.push(JavaScriptSupport.class, support);
renderer.renderMarkup(writer, reply);
environment.pop(JavaScriptSupport.class);
support.commit();
}
};
configuration.add("JavaScriptSupport", javascriptSupport, "after:DocumentLinker");
}
Aggregations