View
Module | ejs.web |
Definition | dynamic class View |
Inheritance | View ![]() |
Specified | ejscript-1.1 |
Stability | Prototype. |
Base class for web framework views.
This class provides the core functionality for all Ejscript view web pages. Ejscript web pages are compiled to create a new View class which extends the View base class. In addition to the properties defined by this class, user view classes will inherit at runtime all public properites of the current controller object. View objects are not instantiated manually by users but are created internally by the web framework.
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
ejs.web | controller | Controller | Current controller. |
View Methods
Qualifiers | Method |
---|---|
aform(action: String, record: Object = null , options: Object = expression): Void | |
Render an asynchronous (ajax) form. | |
alink(text: String, action: String = null , options: Object = expression): Void | |
Emit an asynchronous (ajax) link to an action. | |
button(value: String, buttonName: String = null , options: Object = expression): Void | |
Render a form button. | |
buttonLink(text: String, action: String, options: Object = expression): Void | |
Render a link button. | |
chart(initialData: Array, options: Object = expression): Void | |
Render a chart. | |
checkbox(field: String, choice: String = true , options: Object = expression): Void | |
Render an input checkbox. | |
createSession(timeout: Number = 0): Void | |
Enable session control. | |
d(args: Array): Void | |
Dump objects for debugging. | |
destroySession(): Void | |
Destroy a session. | |
endform(): Void | |
End an input form. | |
extlink(text: String, url: String, options: Object = expression): Void | |
Emit an application relative link. | |
flash(kinds = null , options: Object = expression): Void | |
Emit a flash message area. | |
form(action: String, record: Object = null , options: Object = expression): Void | |
Render a form. | |
getOptions(options: Object): String | |
Map options to a HTML attribute string. | |
html(args: Array): String | |
HTML encode the arguments. | |
image(src: String, options: Object = expression): Void | |
Render an image control. | |
imageLink(image: String, action: String, options: Object = expression): Void | |
Render a clickable image. | |
input(field: String, options: Object = expression): Void | |
Render an input field as part of a form. | |
label(text: String, options: Object = expression): Void | |
Render a text label field. | |
link(text: String, action: String = null , options: Object = expression): Void | |
Emit a link to an action. | |
list(field: String, choices: Object = null , options: Object = expression): Void | |
Emit a selection list. | |
mail(nameText: String, address: String, options: Object = expression): Void | |
Emit a mail link. | |
makeUrl(action: String, id: String = null , options: Object = expression): String | |
Make a URL suitable for invoking actions.param id. | |
radio(field: String, choices: Object, options: Object = expression): Void | |
Emit a radio autton. | |
redirect(action: String, id: String = null , options: Object = expression): Void | |
Redirect to the given action. | |
redirectUrl(url: String, code: Number = 302): Void | |
Redirect the client to a new URL. | |
public | render(): Void |
Process and emit a view to the client. | |
script(url: Object, options: Object = expression): Void | |
Emit a script link. | |
setHeader(key: String, value: String, allowMultiple: Boolean = false): 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. | |
stylesheet(url: Object, options: Object = expression): Void | |
Emit a style sheet link. | |
table(data, options: Object = expression): Void | |
Render a table. | |
tabs(initialData: Array, options: Object = expression): Void | |
Render a tab control. | |
text(field: String, options: Object = expression): Void | |
Render a text input field as part of a form. | |
textarea(field: String, options: Object = expression): Void | |
Render a text area. | |
View(controller: Controller) | |
Constructor method to initialize a new View. | |
write(args: Array): Void | |
Write text to the client. | |
writeHtml(args: Array): Void | |
Write HTML escaped text to the client. |
Method Detail
Render an asynchronous (ajax) form.
- Parameters
action: String Action to invoke when the form is submitted. Defaults to "create" or "update" depending on whether the field has been previously saved. record: Object Model record to edit. [default: null ] options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
url String Use a URL rather than action and controller for the target url.
Emit an asynchronous (ajax) link to an action.
- Description
- The URL is constructed from the given action and the current controller. The controller may be overridden by setting the controller option.
- Parameters
text: String Link text to display. action: String Action to invoke when the link is clicked. [default: null ] options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
controller String Name of the target controller for the given action. url String Use a URL rather than action and controller for the target url.
Render a form button.
- Description
- This creates a button suitable for use inside an input form. When the button is clicked, the input form will be submitted.
- Parameters
value: String Text to display in the button. options: Object Optional extra options. See getOptions for a list of the standard options. Examples: button("OK", "commit") button("Cancel", "commit"). [default: expression] buttonName: String [default: null ]
Render a link button.
- Description
- This creates a button suitable for use outside an input form. When the button is clicked, the associated URL will be invoked.
- Parameters
text: String Text to display in the button. action: String Target action to invoke when the button is clicked. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
Render a chart.
- Description
- The chart control can display static or dynamic tabular data. The client chart control manages sorting by column, dynamic data refreshes, pagination and clicking on rows.
- Parameters
initialData: Array Optional initial data for the control. The data option may be used with the refresh option to dynamically refresh the data. options: Object Object Optional extra options. See also getOptions for a list of the standard options. [default: expression]
- Options
columns Object hash of column entries. Each column entry is in-turn an object hash of options. If unset, all columns are displayed using defaults. kind String Type of chart. Select from: piechart, table, linechart, annotatedtimeline, guage, map, motionchart, areachart, intensitymap, imageareachart, barchart, imagebarchart, bioheatmap, columnchart, linechart, imagelinechart, imagepiechart, scatterchart (and more). onClick String Action or URL to invoke when a chart element is clicked.
- Example
<% chart(null, { data: "getData", refresh: 2" }) %> <% chart(data, { onClick: "action" }) %>
Render an input checkbox.
- Description
- This creates a checkbox suitable for use within an input form.
- Parameters
field: String Name of the field to display. This is used to create a HTML "name" and "id" attribute for the input element. If used inside a model form, it is the field name in the model containing the checkbox value to display. If used without a model, the value to display should be passed via options.value. choice: String Value to submit if checked. Defaults to "true". [default: true ] options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
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 sessionID property in the request object. If a session already exists, this call has no effect. A cookie containing a session ID is automatically created and sent to the client on the first response after creating the session. If SessionAutoCreate is defined in the configuration file, then sessions will automatically be created for every web request and your Ejscript web pages do not need to call createSession. Multiple requests may be sent from a client's browser at the same time. Ejscript will ensure that accesses to the sesssion object are correctly serialized.
- Parameters
timeout: Number Optional timeout for the session in seconds. If ommitted the default timeout is used. [default: 0]
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.
End an input form.
- Description
- This closes an input form initiated by calling the form method.
Emit an application relative link.
- Description
- If invoking an action, it is safer to use \a action.
- Parameters
text: String Link text to display. url: String Action or URL to invoke when the link is clicked. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
Emit a flash message area.
- Parameters
kinds Kinds of flash messages to display. May be a single string ("error", "inform", "message", "warning"), an array of strings or null. If set to null (or omitted), then all flash messages will be displayed. [default: null ] options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
retain Number. Number of seconds to retain the message. If <= 0, the message is retained until another message is displayed. Default is 0.
- Example
<% flash("status") %> <% flash() %> <% flash(["error", "warning"]) %>
Render a form.
- Parameters
action: String Action to invoke when the form is submitted. Defaults to "create" or "update" depending on whether the field has been previously saved. record: Object Model record to edit. [default: null ] options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
url String Use a URL rather than action and controller for the target url.
Map options to a HTML attribute string.
- Parameters
options: Object Optional extra options. See getOptions for a list of the standard options.
- Options
background String Background color. This is a CSS RGB color specification. For example "FF0000" for red. color String Foreground color. This is a CSS RGB color specification. For example "FF0000" for red. data String URL or action to get live data. The refresh option specifies how often to invoke fetch the data. id String Browser element ID for the control. escape Boolean Escape the text before rendering. This converts HTML reserved tags and delimiters into an encoded form. height (Number|String) Height of the table. Can be a number of pixels or a percentage string. Defaults to unlimited. method String HTTP method to invoke. May be: GET, POST, PUT or DELETE. refresh If set, this defines the data refresh period in milliseconds. Only valid if the data option is defined. size (Number|String) Size of the element. style String CSS Style to use for the table. value Default data value to use for the control if not supplied by other means. visible Boolean Make the control visible. Defaults to true. width (Number|String) Width of the table or column. Can be a number of pixels or a percentage string.
- Returns
- A string containing the HTML attributes to emit.
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.
Render an image control.
- Parameters
src: String Optional initial source name for the image. The data option may be used with the refresh option to dynamically refresh the data. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Example
<% image("myPic.gif") %> <% image("myPic.gif", { data: "getData", refresh: 2, style: "myStyle" }) %>
Render a clickable image.
- Description
- This creates an clickable image suitable for use outside an input form. When the image is clicked, the associated URL will be invoked.
- Parameters
image: String Optional initial source name for the image. The data option may be used with the refresh option to dynamically refresh the data. action: String Target action to invoke when the image is clicked. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
Render an input field as part of a form.
- Description
- This is a smart input control that will call the appropriate input control based on the model field data type.
- Parameters
field: String Model field name containing the text data for the control. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Example
<% input(modelFieldName) %> <% input(null, { options }) %>
Render a text label field.
- Description
- This renders an output-only text field. Use text() for input fields.
- Parameters
text: String Optional initial data for the control. The data option may be used with the refresh option to dynamically refresh the data. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Example
<% label("Hello World") %> <% label(null, { data: "getData", refresh: 2, style: "myStyle" }) %>
Emit a link to an action.
- Description
- The URL is constructed from the given action and the current controller. The controller may be overridden by setting the controller option.
- Parameters
text: String Link text to display. action: String Action to invoke when the link is clicked. [default: null ] options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
controller String Name of the target controller for the given action. url String Use a URL rather than action and controller for the target url.
Emit a selection list.
- Parameters
field: String Name of the field to display. This is used to create a HTML "name" and "id" attribute for the input element. If used inside a model form, it is the field name in the model containing the list item to select. If used without a model, the value to select should be passed via options.value. choices: Object Choices to select from. This can be an array list where each element is displayed and the value returned is an element index (origin zero). It can also be an array of array tuples where the second tuple entry is the value to display and the first is the value to send to the app. Or it can be an array of objects such as those returned from a table lookup. If choices is null, the field value is used to construct a model class name to use to return a data grid containing an array of row objects. The first non-id field is used as the value to display. [default: null ] options: Object Extra options Examples: list("stockId", Stock.stockList) list("low", ["low", "med", "high"]) list("low", [["3", "low"], ["5", "med"], ["9", "high"]]) list("low", [{low: 3{, {med: 5}, {high: 9}]) list("Stock Type") Will invoke StockType.findAll() to do a table lookup. [default: expression]
Emit a mail link.
- Parameters
nameText: String Recipient name to display. address: String Mail recipient address. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
Make a URL suitable for invoking actions.param id.
- 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. If the name starts with "." or "/", it is assumed to be a controller name and it is used by itself. id: String The model record ID to select via the URL. Defaults to null. [default: null ] options: Object The options string. [default: expression] options: Object [default: expression]
- Options
url An override url to use. All other args are ignored. query Query string to append to the URL. Overridden by the query arg. controller The name of the controller to use in the URL.
- Returns
- A string URL.
Emit a radio autton.
- Description
- The URL is constructed from the given action and the current controller. The controller may be overridden by setting the controller option.
- Parameters
field: String Name of the field to display. This is used to create a HTML "name" and "id" attribute for the input element. If used inside a model form, it is the field name in the model containing the radio data to display. If used without a model, the value to display should be passed via options.value. choices: Object Array or object containing the option values. If array, each element is a radio option. If an object hash, then they property name is the radio text to display and the property value is what is returned. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
controller String Name of the target controller for the given action. value String Name of the option to select by default.
- Example
radio("priority", ["low", "med", "high"]) radio("priority", {low: 0, med: 1, high: 2}) radio(priority, Message.priorities)
Process and emit a view to the client.
- Description
- Overridden by the views invoked by controllers.
Emit a script link.
- Parameters
url: Object URL for the script to load. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
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.
Set the HTTP response status code.
- Parameters
code: Number HTTP response code to define.
Set the response body mime type.
- Parameters
format: String Mime type for the response. For example "text/plain".
Emit a style sheet link.
- Parameters
url: Object Stylesheet url or array of stylesheets. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
Render a table.
- Description
- The table control can display static or dynamic tabular data. The client table control manages sorting by column, dynamic data refreshes, pagination and clicking on rows. If the table supplies a URL or action for the data parameter, the table data is retrieved asynchronously using Ajax requests on that action/URL value. The action routine should call the table() control to render the data and must set the ajax option to true.
- Parameters
data Data for the control or URL/action to supply data. If data is a String, it is interpreted as a URL or action that will be invoked to supply HTML for the table. In this case, the refresh option defines how frequently to refresh the table data. The data parameter can also be a grid of data, ie. an Array of objects where each object represents the data for a row. The column names are the object property names and the cell text is the object property values. The data parameter can also be a model instance. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
ajax Set to true if the table control is being invoked as part of an Ajax data refresh. click String Action or URL to invoke an element in the table is clicked. The click arg can be is a String to apply to all cells, a single-dimension array of strings for per-row URLs, and a two-dimension array for per cell URLs (order is row/column). columns Object hash of column entries. Each column entry is in-turn an object hash of options. If unset, all columns are displayed using defaults. Column options: align, formatter, header, render, sort, sortOrder, style, width. pageSize Number Number of rows to display per page. Omit or set to <= 0 for unlimited. Defaults to unlimited. pivot Boolean Pivot the table by swaping rows for columns and vice-versa. query URL query string to add to click URLs. Can be a single-dimension array for per-row query strings or a two-dimensional array for per cell (order is row/column). showHeader Boolean Control if column headings are displayed. showId Boolean If a columns option is not provided, the id column is normally hidden. To display, set showId to be true. sort String Enable row sorting and define the column to sort by. sortOrder String Default sort order. Set to "ascending" or "descending".Defaults to ascending. style String CSS style to use for the table. styleColumns Array of styles to use for the table body columns. Can also use the style option in the columns option. styleBody String CSS style to use for the table body cells. styleHeader String CSS style to use for the table header. styleRows Array of styles to use for the table body rows. styleOddRow String CSS style to use for odd data rows in the table. styleEvenRow String CSS style to use for even data rows in the table. title String Table title Column options: - align
- format
- formatter
- header
- render
- sort String Define the column to sort by and the sort order. Set to "ascending" or "descending". Defaults to ascending.
- style
- Example
<% table("getData", { refresh: 2, pivot: true" }) %> <% table(gridData, { click: "edit" }) %> <% table(Table.findAll()) %> <% table(gridData, { click: "edit", sort: "Product", columns: { product: { header: "Product", width: "20%" } date: { format: date('%m-%d-%y) } } }) %>
Render a tab control.
- Description
- The tab control can display static or dynamic tree data.
- Parameters
initialData: Array Optional initial data for the control. The data option may be used with the refresh option to dynamically refresh the data. Tab data is an array of objects -- one per tab. For example: [{"Tab One Label", "action1"}, {"Tab Two Label", "action2"}]. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
Render a text input field as part of a form.
- Parameters
field: String Name of the field to display. This is used to create a HTML "name" and "id" attribute for the input element. If used inside a model form, it is the field name in the model containing the text data to display. If used without a model, the value to display should be passed via options.value. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
escape Boolean Escape the text before rendering. This converts HTML reserved tags and delimiters into an encoded form. style String CSS Style to use for the control. visible Boolean Make the control visible. Defaults to true.
- Example
<% text("name") %>
Render a text area.
- Parameters
field: String Name of the field to display. This is used to create a HTML "name" and "id" attribute for the input element. If used inside a model form, it is the field name in the model containing the text data to display. If used without a model, the value to display should be passed via options.value. options: Object Optional extra options. See getOptions for a list of the standard options. [default: expression]
- Options
Boolean Escape Escape the text before rendering. This converts HTML reserved tags and delimiters into an encoded form. data String URL or action to get data. numCols Number number of text columns. numRows Number number of text rows. style String CSS Style to use for the control. visible Boolean Make the control visible. Defaults to true.
- Example
<% textarea("name") %>
Constructor method to initialize a new View.
- Parameters
controller: Controller Controller to manage this view.
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.
Write HTML escaped text to the client.
- Description
- This call writes the arguments back to the client's browser after mapping all HTML control sequences into safe alternatives. The arguments are converted to strings before writing back to the client and then escaped. The 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.