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.

ParameterDescription
templatethe path of the template to render

jsonView(String attribute)

Returns: JsonView

Creates a view that renders the named page attribute as JSON.

ParameterDescription
attributethe 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.

ParameterDescription
statusthe result's success flag
messagethe result's message text

jsonObjectView(Object o)

Returns: JsonView

Creates a view that renders the given object as JSON.

ParameterDescription
othe object to render as JSON

redirectView(String uri)

Returns: RedirectView

Creates a view that issues a temporary redirect to the given URI.

ParameterDescription
urithe 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.

ParameterDescription
urithe URI to redirect to
permanenttrue 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.

ParameterDescription
templatethe path of the text template to render
contentTypethe 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.

ParameterDescription
hashthe file's content hash
contentTypethe 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.

ParameterDescription
hashthe file's content hash
contentTypethe content type to send with the response
isPerTenanttrue 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.

ParameterDescription
contentNamethe stored content's name, used as the lookup key
contentTypethe 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.

ParameterDescription
dirthe storage directory the content was stored under
contentNamethe stored content's name, used as the lookup key within the directory
contentTypethe 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.

ParameterDescription
fileContentthe bytes to render
contentTpethe 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.

ParameterDescription
fileContentthe stream to copy the response bytes from
contentTpethe content type to send with the response

textView(String text)

Returns: TextView

Creates a view that renders the given fixed text as text/plain.

ParameterDescription
textthe 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.

ParameterDescription
textthe text to render as the response body
contentTypethe content type to send with the response

jsonResult(boolean result)

Returns: JsonResult

Creates a JsonResult with the given success flag and no message.

ParameterDescription
resultthe result's success flag

jsonResult(boolean result, String message)

Returns: JsonResult

Creates a JsonResult with the given success flag and message.

ParameterDescription
resultthe result's success flag
messagethe 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.

ParameterDescription
resultthe result's success flag
messagesthe 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.

ParameterDescription
resultthe result's success flag
messagesthe 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.

ParameterDescription
resultthe result's success flag
messagethe result's message text
nextHrefthe 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.

ParameterDescription
datathe data to attach to the result
messagethe result's message text, or null for none

jsonDataResult(Object data)

Returns: JsonResult

Creates a successful JsonResult carrying the given data and no message.

ParameterDescription
datathe 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.

ParameterDescription
rthe 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.

ParameterDescription
rowsthe 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.

ParameterDescription
rowsResultthe 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.

ParameterDescription
headersthe column header row to write
rowsResultthe 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.

ParameterDescription
messagethe message to log and attach to the exception
pagethe 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.

ParameterDescription
messagethe message to log and attach to the exception
pagethe 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.

ParameterDescription
messagethe 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.

ParameterDescription
messagethe 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.

ParameterDescription
messagethe message to log and attach to the exception
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.