public interface Controller
Controller
is responsible for handling incoming HTTP requests.
Implementing classes must wear a Register
to make them visible to the MVC kernel.
Each class can define one to many methods wearing a Routed
annotation in order to handle a specific URI.
Each method must have WebContext
as first parameter and a string parameter for each variable in the url.
Therefore a method handling a static url looks like this:
{@literal @}Routed("/system/console")
public void console(WebContext ctx) {
ctx.respondWith().cached().template("view/system/console.html");
}
URIs can have numbered parameters like /tests/:1/foos/:2
. This method needs to have two string
parameters (e.g. void foo(WebContext ctx, String testId, String fooId)
).
Being an async framework, the method may return without handling the request defined by the given
WebContext
. However, one should ensure, that _some_ information is sent before a timeout occurs or the
idle-handler must be disabled for this request (dangerous).
Although this can be used to respond with JSON, also bear in mind, that services
(StructuredService
) can be used to provide both, an XML and JSON interfaces at once.
Modifier and Type | Method and Description |
---|---|
void |
onError(WebContext ctx,
sirius.kernel.health.HandledException error)
In case processing a request via a method fails (throws an exception), this method will be called.
|
void onError(WebContext ctx, sirius.kernel.health.HandledException error)
This provides a convenient way to render a "fallback" page like a list view, if a specialized details view or something thereof fails.
ctx
- the context containing the requesterror
- the error which occurredCopyright © 2018. All rights reserved.