T
- The type of object this renderer renderspublic abstract class RendererSupport<T> extends Object implements Renderer<T>
Renderer
super class that provides a getType()
implementation based on the generic type of the impl.
Implementations need only to declare the type they render as the value for type variable T
and implement render(ratpack.handling.Context, Object)
.
import ratpack.handling.Context; import ratpack.render.RendererSupport; // A type of thing to be rendered public class Thing { private final String name; public Thing(String name) { this.name = name; } public String getName() { return this.name; } } // Renderer implementation public class ThingRenderer extends RendererSupport<Thing> { public void render(Context context, Thing thing) { context.render("Thing: " + thing.getName()); } }
Modifier | Constructor and Description |
---|---|
protected |
RendererSupport()
Constructor.
|
protected |
RendererSupport(Class<?> type)
Constructor.
|
protected RendererSupport()
Determines the value for getType()
by reflecting for T
protected RendererSupport(Class<?> type)
Only necessary for abstract implementations that propagate the generic type T
.
Almost all implementations should use the RendererSupport()
default constructor}.
type
- the most specialised parent type of this
that does not have a concrete type for T
public Class<T> getType()
T
).public abstract void render(Context context, T object) throws Exception
Calling this method will finalize the processing, sending the response to the client.
Any errors that occur during rendering will be sent to Context.error(Exception)
.