Controller

Moduleejs.web
Namespace"ejs.web"
Definition class Controller
InheritanceController inherit Object

Web framework controller.

Part of the Ejscript web MVC framework.


Properties

QualifiersPropertyTypeDescription
ejs.web actionNameStringName of the action being run.
public applicationObjectStores application global data. The application array provides a means to store persistent information to be shared across all clients using an application. Objects and variables stored in the application array will live until either explicitly deleted or the web server exits. The application array does not persist over system reboots. The elements are User defined.
ejs.web controllerNameStringLower case controller name.
public flashObjectFlash messages to display on the next screen (only) "inform" Informational / postitive feedback "message" Neutral feedback (reminders, suggestions. ) "warning" Negative feedback (Warnings and errors) "error" Negative error (Warnings and errors).
public hostHostHost object.
public paramsObjectForm parameters.
public requestRequestThe request object stores details of the incoming client's request.
public responseResponseThe response object stores details of the response going back to the client.
public sessionObjectStores session state information. The session array will be created automatically if SessionAutoCreate is defined or if a session is started via the useSession() or createSession() functions. Sessions are shared among requests that come from a single client. This may mean that multiple requests access the same session concurrently. Ejscript ensures that such accesses are serialized. The elements are user defined.

Controller Methods

QualifiersMethod
cache(enable: Boolean): Void
 Add a cache-control header to direct the browser to not cache the response.
Controller()
 Controller constructor.
createSession(timeout: Number): Void
 Enable session control.
destroySession(): Void
 Destroy a session.
discardOutput(): Void
 Discard all prior output.
doAction(act: String): Void
 Invoke the named action.
error(msg: String): Void
 Send an error response back to the client.
escapeHtml(s: String): String
 Transform a string to be safe for output into an HTML web page.
flashMessages(args: Array): String
 Return the aggregated flash messages.
html(args: Array): String
 HTML encode the arguments.
inform(msg: String): Void
 Send a positive notification to the user.
keepAlive(on: Boolean): Void
 Control whether the HTTP connection is kept alive after this request.
loadView(path: String): Void
 Load a view.
makeUrl(action: String, id: String, options: Object): String
 Make a URL suitable for invoking actions.
action missing(): Void
 Missing action method.
redirect(action: String, id: String, options: Object): Void
 Redirect to the given action Options: id controller.
redirectUrl(url: String, code: Number): Void
 Redirect the client to a new URL.
render(args: Array): Void
 Render the raw arguments back to the client.
renderFile(filename: String): Void
 Render a file's contents.
renderRaw(args: Array): Void
 Render raw data.
renderView(viewName: String): Void
 Render a view template.
setCookie(name: String, value: String, lifetime: Number, path: String, secure: Boolean): Void
 Define a cookie header to include in the reponse.
setHeader(key: String, value: String, allowMultiple: Boolean): Void
 Of the format "keyword: value".
setHttpCode(code: Number): Void
 Set the HTTP response status code.
setMimeType(format: String): Void
 Set the response body mime type.
action StandAlone(): Void
 Action routine for use with stand-alone web pages.
statusMessage(args: Array)
 Send a status message to any registered status message view controls.
unescapeHtml(s: String): String
 Transform an escaped string into its original contents.
warn(msg: String): Void
 Send a warning message back to the client for display in the flash area.
write(args: Array): Void
 Write text to the client.
writeHtml(args: Array): Void
 Send text back to the client which must first be HTML escaped.
writeRaw(args: Array): Void

Method Detail

cache(enable: Boolean): Void

Add a cache-control header to direct the browser to not cache the response.

Parameters
enable: Boolean [default: true]

Controller()

Controller constructor.


createSession(timeout: Number): Void

Enable session control.

Description
This enables session state management for this request and other requests from the browser. If a session has not already been created, this call creates a session and sets the.
Parameters
timeout: Number Optional timeout for the session in seconds. If ommitted the default timeout is used.

destroySession(): Void

Destroy a session.

Description
This call destroys the session state store that is being used for the current client. If no session exists, this call has no effect.

discardOutput(): Void

Discard all prior output.


doAction(act: String): Void

Invoke the named action.

Description
Internal use only. Called from ejsWebService.c.
Parameters
act: String Action name to invoke

error(msg: String): Void

Send an error response back to the client.

Description
This calls discard.
Parameters
msg: String Message to display

escapeHtml(s: String): String

Transform a string to be safe for output into an HTML web page.

Description
It does this by changing the ">", "<" and '"' characters into their ampersand HTML equivalents.
Parameters
s: String input string
Returns
A transformed HTML escaped string.

flashMessages(args: Array): String

Return the aggregated flash messages.

Parameters
args: Array Kinds of flash messages. Should be an array of inform, message, warning or error

html(args: Array): String

HTML encode the arguments.

Parameters
args: Array Variable arguments that will be converted to safe html
Returns
A string containing the encoded arguments catenated together.

inform(msg: String): Void

Send a positive notification to the user.

Parameters
msg: String Message to display

keepAlive(on: Boolean): Void

Control whether the HTTP connection is kept alive after this request.


loadView(path: String): Void

Load a view.

Description
If path is not supplied, use the default view for the current action.
Parameters
path: String

makeUrl(action: String, id: String, options: Object): String

Make a URL suitable for invoking actions.

Description
This routine will construct a URL Based on a supplied action name, model id and options that may contain an optional controller name. This is a convenience routine remove from applications the burden of building URLs that correctly use action and controller names.
Parameters
action: String The action name to invoke in the URL
id: String The model record ID to select via the URL. Defaults to null.
options: Object The options string

Options

url: An — override url to use. All other args are ignored.

controller: The — name of the controller to use in the URL.


action missing(): Void

Missing action method.

Description
This method will be called if the requested action routine does not exist.

redirect(action: String, id: String, options: Object): Void

Redirect to the given action Options: id controller.

Parameters
id: String
options: Object

redirectUrl(url: String, code: Number): Void

Redirect the client to a new URL.

Description
This call redirects the client's browser to a new location specified by the.
Parameters
url: String Url to redirect the client to
code: Number Optional HTTP redirection code

render(args: Array): Void

Render the raw arguments back to the client.

Description
The args are converted to strings.

renderFile(filename: String): Void

Render a file's contents.


renderRaw(args: Array): Void

Render raw data.


renderView(viewName: String): Void

Render a view template.

Parameters
viewName: String

setCookie(name: String, value: String, lifetime: Number, path: String, secure: Boolean): Void

Define a cookie header to include in the reponse.

Parameters
secure: Boolean [default: false]

setHeader(key: String, value: String, allowMultiple: Boolean): Void

Of the format "keyword: value".

Description
If a header has already been defined and \a allowMultiple is false, the header will be overwritten. If \a allowMultiple is true, the new header will be appended to the response headers and the existing header will also be output. NOTE: case does not matter in the header keyword.
Parameters
allowMultiple: Boolean If false, overwrite existing headers with the same keyword. If true, all headers are output. [default: false]

setHttpCode(code: Number): Void

Set the HTTP response status code.

Parameters
code: Number HTTP status code to define

setMimeType(format: String): Void

Set the response body mime type.

Parameters
format: String Mime type for the response. For example "text/plain".

action StandAlone(): Void

Action routine for use with stand-alone web pages.

Description
If a web page with a '.ejs' extension is requested, it will be processed stand-alone, ie. outside any Ejscript application context. In this case, the StandAlone method is used as the action routine.

statusMessage(args: Array)

Send a status message to any registered status message view controls.


unescapeHtml(s: String): String

Transform an escaped string into its original contents.

Description
This reverses the transformation done by $escapeHtml. It does this by changing ", >, < back into ", < and >.
Parameters
s: String input string
Returns
A transformed string.

warn(msg: String): Void

Send a warning message back to the client for display in the flash area.

Parameters
msg: String Message to display

write(args: Array): Void

Write text to the client.

Description
This call writes the arguments back to the client's browser. The arguments are converted to strings before writing back to the client. Text written using write, will be buffered up to a configurable maximum. This allows text to be written prior to setting HTTP headers with setHeader.
Parameters
args: Array Text or objects to write to the client

writeHtml(args: Array): Void

Send text back to the client which must first be HTML escaped.

Parameters
args: Array Objects to emit

writeRaw(args: Array): Void

Embedthis Software LLC, 2003-2009. All rights reserved. Embedthis is a trademark of Embedthis Software LLC.