Search in sources :

Example 1 with DefaultObjectRenderer

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

the class TapestryModule method contributeObjectRenderer.

/**
 * Contributes a default object renderer for type Object, plus specialized
 * renderers for {@link org.apache.tapestry5.http.services.Request}, {@link org.apache.tapestry5.commons.Location},
 * {@link org.apache.tapestry5.ComponentResources}, {@link org.apache.tapestry5.EventContext},
 * {@link AvailableValues},
 * List, and Object[].
 */
@SuppressWarnings("unchecked")
public void contributeObjectRenderer(MappedConfiguration<Class, ObjectRenderer> configuration, @InjectService("LocationRenderer") ObjectRenderer locationRenderer, final TypeCoercer typeCoercer) {
    configuration.add(Object.class, new DefaultObjectRenderer());
    configuration.addInstance(Request.class, RequestRenderer.class);
    configuration.add(Location.class, locationRenderer);
    ObjectRenderer preformatted = new ObjectRenderer<Object>() {

        public void render(Object object, MarkupWriter writer) {
            writer.element("pre");
            writer.write(typeCoercer.coerce(object, String.class));
            writer.end();
        }
    };
    configuration.addInstance(List.class, ListRenderer.class);
    configuration.addInstance(Object[].class, ObjectArrayRenderer.class);
    configuration.addInstance(ComponentResources.class, ComponentResourcesRenderer.class);
    configuration.addInstance(EventContext.class, EventContextRenderer.class);
    configuration.add(AvailableValues.class, new AvailableValuesRenderer());
}
Also used : AvailableValuesRenderer(org.apache.tapestry5.internal.renderers.AvailableValuesRenderer) ObjectRenderer(org.apache.tapestry5.services.ObjectRenderer) DefaultObjectRenderer(org.apache.tapestry5.services.DefaultObjectRenderer) DefaultObjectRenderer(org.apache.tapestry5.services.DefaultObjectRenderer) JSONObject(org.apache.tapestry5.json.JSONObject) MarkupWriter(org.apache.tapestry5.MarkupWriter)

Aggregations

MarkupWriter (org.apache.tapestry5.MarkupWriter)1 AvailableValuesRenderer (org.apache.tapestry5.internal.renderers.AvailableValuesRenderer)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 DefaultObjectRenderer (org.apache.tapestry5.services.DefaultObjectRenderer)1 ObjectRenderer (org.apache.tapestry5.services.ObjectRenderer)1