Factory for the View objects a controller returns to render a response, plus helpers for building JsonResult objects and throwing common HTTP error responses. A single shared instance is bound into server-side JS as the "views" global, so app code builds responses with calls like views.templateView(...), views.jsonView(...), views.csvView(...) and returns the result from a controller function. Each factory method wraps a matching View implementation constructor.
Group: Views
Methods
templateView(String template) · jsonView(String attribute) · jsonView(boolean status, String message) · jsonObjectView(Object o) · redirectView(String uri) · redirectView(String uri, boolean permanent) · textTemplateView(String template, String contentType) · fileView(String hash, String contentType) · fileView(String hash, String contentType, boolean isPerTenant) · contentFileView(String contentName, String contentType) · contentFileView(String dir, String contentName, String contentType) · binaryView(byte[] fileContent, String contentTpe) · binaryView(InputStream fileContent, String contentTpe) · textView(String text) · textView(String text, String contentType) · jsonResult(boolean result) · jsonResult(boolean result, String message) · jsonResult(boolean result, List<String> messages) · jsonResult(boolean result, String[] messages) · jsonResult(boolean result, String message, String nextHref) · jsonDataResult(Object data, String message) · jsonDataResult(Object data) · searchResponseView(KSearchResponse r) · contentEditorView() · csvView(List<List> rows) · rowsResultCsvView(RowsResult rowsResult) · rowsResultCsvView(String[] headers, RowsResult rowsResult) · throwNotAuthorizedException(String message, Resource page) · throwBadRequestException(String message, Resource page) · throwNotFoundException(String message) · throwServerException(String message) · throwPasswordInvalidException(String message)
templateView(String template)
Returns: TemplateView
Creates a view that renders the given HTML template path against the current resource.
| Parameter | Description |
|---|---|
template | the path of the template to render |
jsonView(String attribute)
Returns: JsonView
Creates a view that renders the named page attribute as JSON.
| Parameter | Description |
|---|---|
attribute | the name of the page attribute holding the object to render as JSON |
jsonView(boolean status, String message)
Returns: JsonView
Creates a view that renders a simple success/failure JsonResult as JSON.
| Parameter | Description |
|---|---|
status | the result's success flag |
message | the result's message text |
jsonObjectView(Object o)
Returns: JsonView
Creates a view that renders the given object as JSON.
| Parameter | Description |
|---|---|
o | the object to render as JSON |
redirectView(String uri)
Returns: RedirectView
Creates a view that issues a temporary redirect to the given URI.
| Parameter | Description |
|---|---|
uri | the URI to redirect to |
redirectView(String uri, boolean permanent)
Returns: RedirectView
Creates a view that redirects to the given URI, as a permanent redirect if requested.
| Parameter | Description |
|---|---|
uri | the URI to redirect to |
permanent | true to issue a permanent redirect rather than a temporary one |
textTemplateView(String template, String contentType)
Returns: TextTemplateView
Creates a view that renders the given text template path with the given response content type.
| Parameter | Description |
|---|---|
template | the path of the text template to render |
contentType | the content type to send with the response |
fileView(String hash, String contentType)
Returns: FileHashView
Creates a view that streams a stored file, looked up by its content hash from the server-wide blob store.
| Parameter | Description |
|---|---|
hash | the file's content hash |
contentType | the content type to send with the response |
fileView(String hash, String contentType, boolean isPerTenant)
Returns: FileHashView
Creates a view that streams a stored file, looked up by its content hash. If isPerTenant is true, the content is retrieved from the current tenant's own blob store rather than the server-wide one.
| Parameter | Description |
|---|---|
hash | the file's content hash |
contentType | the content type to send with the response |
isPerTenant | true to read from the current tenant's own blob store |
contentFileView(String contentName, String contentType)
Returns: ContentFileView
Creates a view that streams stored content looked up by content name, from the top level of tenant storage.
| Parameter | Description |
|---|---|
contentName | the stored content's name, used as the lookup key |
contentType | the content type to send with the response |
contentFileView(String dir, String contentName, String contentType)
Returns: ContentFileView
Creates a view that streams stored content looked up by directory and content name.
| Parameter | Description |
|---|---|
dir | the storage directory the content was stored under |
contentName | the stored content's name, used as the lookup key within the directory |
contentType | the content type to send with the response |
binaryView(byte[] fileContent, String contentTpe)
Returns: BinaryView
Creates a view that streams the given byte array as binary content, with the given content type.
| Parameter | Description |
|---|---|
fileContent | the bytes to render |
contentTpe | the content type to send with the response |
binaryView(InputStream fileContent, String contentTpe)
Returns: BinaryView
Creates a view that streams the given input stream as binary content, with the given content type.
| Parameter | Description |
|---|---|
fileContent | the stream to copy the response bytes from |
contentTpe | the content type to send with the response |
textView(String text)
Returns: TextView
Creates a view that renders the given fixed text as text/plain.
| Parameter | Description |
|---|---|
text | the text to render as the response body |
textView(String text, String contentType)
Returns: TextView
Creates a view that renders the given fixed text with the given content type.
| Parameter | Description |
|---|---|
text | the text to render as the response body |
contentType | the content type to send with the response |
jsonResult(boolean result)
Returns: JsonResult
Creates a JsonResult with the given success flag and no message.
| Parameter | Description |
|---|---|
result | the result's success flag |
jsonResult(boolean result, String message)
Returns: JsonResult
Creates a JsonResult with the given success flag and message.
| Parameter | Description |
|---|---|
result | the result's success flag |
message | the result's message text |
jsonResult(boolean result, List<String> messages)
Returns: JsonResult
Creates a JsonResult with the given success flag and a list of messages.
| Parameter | Description |
|---|---|
result | the result's success flag |
messages | the result's message texts |
jsonResult(boolean result, String[] messages)
Returns: JsonResult
Creates a JsonResult with the given success flag and a list of messages given as an array.
| Parameter | Description |
|---|---|
result | the result's success flag |
messages | the result's message texts |
jsonResult(boolean result, String message, String nextHref)
Returns: JsonResult
Creates a JsonResult with the given success flag, message and a URL for the client to navigate to next.
| Parameter | Description |
|---|---|
result | the result's success flag |
message | the result's message text |
nextHref | the URL the client should navigate to next |
jsonDataResult(Object data, String message)
Returns: JsonResult
Creates a successful JsonResult carrying the given data and an optional message.
| Parameter | Description |
|---|---|
data | the data to attach to the result |
message | the result's message text, or null for none |
jsonDataResult(Object data)
Returns: JsonResult
Creates a successful JsonResult carrying the given data and no message.
| Parameter | Description |
|---|---|
data | the data to attach to the result |
searchResponseView(KSearchResponse r)
Returns: SearchResponseView
Creates a view that writes an Elasticsearch search response directly to the response as JSON.
| Parameter | Description |
|---|---|
r | the search response to write |
contentEditorView()
Returns: ContentEditorView
Creates a view that renders the built-in rich content editor page.
csvView(List<List> rows)
Returns: CsvView
Creates a view that renders the given rows as CSV.
| Parameter | Description |
|---|---|
rows | the rows to render, each entry a row of column values |
rowsResultCsvView(RowsResult rowsResult)
Returns: RowsResultCsvView
Creates a view that renders a table query result as CSV, with no explicit column headers.
| Parameter | Description |
|---|---|
rowsResult | the query result to render as CSV |
rowsResultCsvView(String[] headers, RowsResult rowsResult)
Returns: RowsResultCsvView
Creates a view that renders a table query result as CSV, using the given column headers.
| Parameter | Description |
|---|---|
headers | the column header row to write |
rowsResult | the query result to render as CSV |
throwNotAuthorizedException(String message, Resource page)
Returns: void
Logs a warning and throws a NotAuthorizedException with the given message, for a controller to reject an unauthorised request.
| Parameter | Description |
|---|---|
message | the message to log and attach to the exception |
page | the resource the request was for |
throwBadRequestException(String message, Resource page)
Returns: void
Logs a warning and throws a BadRequestException with the given message, for a controller to reject a malformed request.
| Parameter | Description |
|---|---|
message | the message to log and attach to the exception |
page | the resource the request was for |
throwNotFoundException(String message)
Returns: void
Logs a warning and throws a NotFoundException with the given message, for a controller to signal a missing resource.
| Parameter | Description |
|---|---|
message | the message to log and attach to the exception |
throwServerException(String message)
Returns: void
Logs a warning and throws a plain Exception with the given message, for a controller to signal an unclassified server error.
| Parameter | Description |
|---|---|
message | the message to log and attach to the exception |
throwPasswordInvalidException(String message)
Returns: void
Logs a warning and throws a PasswordInvalidException with the given message, for a controller to reject an invalid password.
| Parameter | Description |
|---|---|
message | the message to log and attach to the exception |