public class BasicController extends Object implements Controller
Controller
providing convenience methods and default routing.
The annotation DefaultRoute
can be added to an existing Routed
. In case any other route
throws an error, the default route is invoked and will display the error. This can be used to automatically
jump back to a list view in case an edit view throws an error. Using this behavior is more transparent for the
user than just jumping to a random error page.
Modifier and Type | Field and Description |
---|---|
protected Consumer<WebContext> |
defaultRoute |
Constructor and Description |
---|
BasicController()
Creates a new instance of the controller and tries to determine the
DefaultRoute which
is used in case another route throws an error. |
Modifier and Type | Method and Description |
---|---|
protected void |
assertNotNull(Object obj)
Asserts that the given object is non-null.
|
protected void |
assertPermission(String permission)
Asserts that the current user has the given permission.
|
void |
fail(WebContext ctx,
sirius.kernel.health.HandledException error)
Aborts the request with an error.
|
protected UserInfo |
getUser()
Obtains the currently active user.
|
protected boolean |
hasPermission(String permission)
Determines if the current user has the given permission.
|
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 |
showDeletedMessage()
Displays a genric "Object was deleted" message.
|
void |
showSavedMessage()
Displays a generic "Changes have been saved" message.
|
protected Consumer<WebContext> defaultRoute
public BasicController()
DefaultRoute
which
is used in case another route throws an error.protected UserInfo getUser()
protected boolean hasPermission(String permission)
Note that a routed method may also wear Permission
or LoginRequired
to signal the required permissions of a user.
permission
- the permission being requiredprotected void assertPermission(String permission)
If the permission is not present, an appropriate error is thrown.
permission
- the permission being requiredprotected void assertNotNull(Object obj)
Throws an appropriate error if the object is null.
obj
- the object to be checkedpublic void showSavedMessage()
public void showDeletedMessage()
public void fail(WebContext ctx, sirius.kernel.health.HandledException error)
This is used if no default route is present or if the default route itself fails.
Most of the time this method should not be called directly, rather a HandledException should be thrown.
ctx
- the current requesterror
- the error which occuredpublic void onError(WebContext ctx, sirius.kernel.health.HandledException error)
Controller
This provides a convenient way to render a "fallback" page like a list view, if a specialized details view or something thereof fails.
onError
in interface Controller
ctx
- the context containing the requesterror
- the error which occurredCopyright © 2018. All rights reserved.