WebSnapTM Server-side Scripting
This is a draft document written by Jim Tierney, WebSnap Architect. It will be part of the updated documentation for
WebSnap we will be releasing as soon as we can. I'm publishing it on the community site in the interest of making more
information on WebSnap available. For additional discussions on websnap, see the
borland.public.delphi.internet.websnap newsgroup, which is already quite active. This document describes the objects,
properties, and methods used to develop server-side script for WebSnap applications. This script is supported by special
Delphi classes, called Adapters, that can be used with ActiveScript.
The code samples are in a smaller font size some of the lines of code are long
and wrapping may affect the operation of some of the code.
Because some people may want to print this article out for reference, I have left the wrapping of the script
intact but reduced the font size. If you want to modify the font size, simply download this HTML page and modify the
.code line in the stylesheet to indicate your desired font size.
You can download Jim's original version of this document from
CodeCentral.
We'll try to keep more information on WebSnap coming until the official updated documentation is
available for download.
Global Objects
The following global objects can be
referenced with server-side script.
| Object |
Description
|
|
Application
|
Use the Application object to
access fields and actions of the application adapter, such as the
Title field. |
|
EndUser
|
Use to EndUser object to
access fields and actions of the end-user adapter, such as the
DisplayName for the end-user, the Login action, and Logout
action. |
|
Modules
|
Use the Modules object to
reference a data module or page module by name. The Modules
variables can also be used to enumerate the modules of the
application. |
|
Pages
|
Use the Pages object to
reference a registered page by name. The Pages variables can also
be used to enumerate the registered pages of the application. |
|
Page
|
Use the Page object to access
the properties of the page being generated such as the page
Title. |
|
Producer
|
Use the Producer object to
write HTML content that may include transparent tags. |
|
Request
|
Use the Request object to
access the properties and methods of the HTTP request. |
|
Response
|
Use the Request object to
write HTML content to the HTTP response. |
|
Session
|
Use the Session object to
access the properties of the end-user's session. |
Object Types
Some object have properties that are
objects. The following table lists the object types. Note that
these type names are for documentation purposes. Server-side script
does not recognize these names.
| Type Name |
Description
|
| AdapterType |
AdapterType defines the
properties and methods of an adapter. Adapters can be accessed by
name as a property of a Module. |
|
AdapterActionType
|
AdapterActionType defines the
properties and methods of an adapter action. Actions are referenced
by name as a property of an adapter. |
| AdapterErrorsType |
AdapterErrorsType defines the
Errors property of an adapter. The Errors property is used to list
errors that occurred when executing an action or generating a
page. |
| AdapterFieldType |
AdapterFieldType defines the
properties and methods of an adapter field. Fields are referenced
by name as a property of an Adapter. |
|
AdapterFieldValuesType
|
AdapterFieldValuesType defines
the properties and methods of an adapter field's Values
property. |
|
AdapterFieldValuesListType
|
AdapterFieldValuesListType
defines the property and methods of an adapter field's ValuesList
property. |
| AdapterHiddenFieldsType |
AdapterHiddenFieldsType
defines the HiddenFields and HiddenRecordFields property of an
adapter. |
|
AdapterImageType
|
AdapterImageType defines the
Image property of adapter fields and adapter actions. |
| ModuleType |
ModuleType defines the
properties of a Module. A Module can be accessed by name as a
property of the Modules variable. |
|
PageType
|
PageType defines the
properties of a page. A page can be accessed by name as a property
of the Pages object. The page being generated can be accessed using
the Page object. |
Examples
The following JavaScript examples
demonstrate how many of the server-side scripting properties and
methods are used.
| Example |
Description
|
| Example1 |
Uses the
Application.QualifyFilename method to generate a relative path
reference to an image. |
|
Example2
|
Declares a variable that
references a module. |
| Example3 |
Enumerates the modules in the
web application and display their names in an HTML table. |
| Example4 |
Declares a variable that
references a registered page |
| Example5 |
Enumerates registered pages to
generate a menu of hyperlinks to published pages. |
| Example6 |
Enumerates registered pages to
generate a menu of hyperlinks to the published pages' default
actions. |
| Example7 |
Writes a list of errors
detected by an adapter. |
| Example8 |
Enumerates all of the action
objects of an adapter to display action object property values in
an HTML table. |
| Example9 |
Enumerates the records of an
adapter to display adapter field values in an HTML table. |
| Example10 |
Generates an HTML form to edit
adapter fields and submit adapter actions. |
| Example11 |
The GotoPage action has an
array of commands. The commands are enumerated to generate a
hyperlink to jump to each page. |
| Example12 |
Displays an adapter field's
image using the <img> tag. |
| Example13 |
Displays an adapter field
using the <select> and <option> tags. |
| Example14 |
Displays an adapter field as a
group of check boxes. |
| Example15 |
Displays an adapter field's
values using <ul> and <li> tags. |
| Example16 |
Displays an adapter field as a
group of radio buttons. |
| Example17 |
Uses the adapter field's
DisplayStyle, InputStyle and ViewMode properties to generate
HTML. |
| Example18 |
Uses properties of the
Application object and the Page object to generate a page
heading. |
| Example19 |
Uses properties of
the EndUser object to display the end-user's name, the login
command, and the logout command. |
| Example20 |
Lists the scriptable objects
in a module. |
| Example21 |
Uses the adapter
actions's DisplayStyle property to generate HTML. |
| Example22 |
Generate an HTML table to update multiple detail records.
|
Adapter
Defines the properties and methods of an
adapter. Adapters can be accessed by name as a property of a
Module.
Adapters contain field components and
action components that represent data items and commands,
respectively. Server-side script statements access the value of
adapter fields and the parameters of adapter actions in order to
build HTML forms and tables.
Properties
Actions: Enumerator
See also Fields, Example8
Enumerates the action objects. Use the
Actions property to loop through the actions of an adapter.
CanModify: boolean, read
See also CanView, AdapterFieldType.CanView,
Indicates whether the end-user has rights
to modify fields of this adapter. Use the CanModify property to
dynamically generate HTML that is sensitive to the end-user's
rights. For example, use an <input> element if CanModify is
True. Use <p> if CanModify is False.
CanView: Boolean, read
See also CanModify, AdapterFieldType.CanModify
Indicates whether the end-user has rights
to view fields of this adapter. Use the CanModify property to
dynamically generate HTML that is sensitive to the end-user's
rights.
ClassName_: text, read
See also Name_
Identifies the VCL class name of the
adapter component.
Errors: AdapterErrors, read
See also AdapterErrorsType, Example7
Enumerates the errors that were detected
while processing an HTTP request.
Adapters capture errors that occur will
generating an HTML page or executing an adapter action. The Errors object is used to
enumerate the errors and display error messages on an HTML
page.
Fields: Enumerator
See also Actions
Enumerates the field objects. Use the
Fields property to loop through the fields of an adapter.
HiddenFields:
AdapterHiddenFields
See also HiddenRecordFields, AdapterHiddenFieldsType,
Example10, Example22
HiddenFields defines the hidden input
fields that pass adapter state information. An example of state information
is TDataSetAdapter’s mode. "Edit" and "Insert" are two
possible mode values.
When TDataSetAdapter is used to generate an HTML form, the
HiddenFields object will define a hidden field for the mode. When the HTML form is
submitted, the HTTP request will contain this hidden field
value. When executing
an action, the mode value is extracted from the HTTP request. If the mode is "Insert", a
new row is inserted into the dataset. If the mode is "Edit", a dataset
row is updated.
HiddenRecordFields: AdapterHiddenFields
See also HiddenFields, AdapterHiddenFieldsType, Example10, Example22
HiddenRecordFields defines the hidden input
fields that pass state information needed by each row or record in
the HTML form. For example, when TDataSetAdapter
is used to generate an HTML form, the HiddenRecordFields object
will define a hidden field that identifies a key value for each row
in an HTML table. When
the HTML form is submitted, the HTTP request will contain these
hidden field values.
When executing an action that updates multiple rows in a dataset,
TDataSetAdapter uses these key values to locate the rows to
update.
Mode: text, read/write
See also Example10
Sets or gets the adapter’s mode.
Some adapters support a mode. For example, the TDataSetAdapter
supports "Edit", "Insert", "Browse", and "Query" modes. The mode affects the behavior of
the adapter. When the
TDataSetAdapter is in "Edit" mode, a submitted form updates a row
in a table. When the TDataSetAdapter is in "Insert" mode, a
submitted form inserts a row in a table.
Name_: text, read
Identifies the variable name of the
adapter.
Records: Enumerator, read
See also Example9
Enumerates the records of the adapter. Use
the Records property to loop through the adapter records to
generate an HTML table.
AdapterActionType
See also AdapterType, AdapterFieldType
AdapterAction defines the properties and
methods of an adapter action.
Properties
Array: Enumerator
See also Example11
Enumerates the commands of an adapter
action. Use the Array property to loop through the commands.
Array will be Null if the action does not support multiple
commands.
TAdapterGotoPageAction is an example of an
action that has multiple commands. This action has a command for
each page defined by the parent adapter. The Array property is used
to generate a series of hyperlinks so that the end-user can user
clicks on a hyperlink to jump to a page.
AsFieldValue: text, read
See also AsHREF, Example10 , Example21
Provides a text value that can be submitted
in a hidden field.
AsFieldValue identifies the name of the
action and the action's parameters. Put this value in a hidden
field called "__act". When the HTML form is submitted, the adapter
dispatcher extracts the value from the HTTP request and uses the
value to locate and call the adapter action.
AsHREF: text, read
See also AsFieldValue, Example11
Provides a text value that can be used as
the href attribute value in an <a> tag.
AsHREF identifies the name of the action
and the action's parameters. Put this value in an anchor tag to
submit a request to execute this action. Note that an anchor tag on an
HTML form will not submit the form. If the action makes use of
submitted form values then use a hidden form field and AsFieldValue
to identify the action.
CanExecute:
Boolean, read
Indicates whether the end-user has rights
to execute this action.
DisplayLabel: text, read
See also Example21
Suggests a DisplayLabel for this adapter
action.
DisplayStyle: string, read
See also Example21
Suggests an HTML display style for this
action.
Server-side script may use the DisplayStyle
to determine how to generate HTML. The built in adapters may return
one of the following display styles.
| ‘’ |
Undefined display style |
| ‘Button’ |
Display as <input
type=”submit”> |
| 'Anchor' |
Use <a>. |
Enabled: Boolean, read
See also Example21
Indicates whether this action should be
enabled on the HTML page.
Name: string,
read
Provides the variable name of this adapter
action
Visible: Boolean, read
Indicates whether this adapter field should
be visible on the HTML page.
Methods
LinkToPage(PageSuccess, PageFail): AdapterAction,
read
See also Example10, Example11, Example21, Page,
AdapterActionType
Use LinkToPage to specify pages to display
after the action executes. The first parameter is the name of the
page to display if the action executes successfully. The second
parameter is the name of the page to display if errors occur during
execution.
AdapterErrorsType
See also AdapterType.Errors
AdapterErrors defines the properties of
an adapter's errors property.
Properties
Field: AdapterField, read
See also AdapterFieldType
Identifies the adapter field that caused an
error.
This property will be Null if the error is
not associated with a particular adapter field.
ID: integer, read
Provides the numeric identifier for an
error.
This property will be zero if an ID is not
defined.
Message: text, read
See also Example7
Provides a text description of the
error.
AdapterFieldType
See also AdapterType, AdapterActionType
AdapterField defines the properties and
methods of an adapter field.
Properties
CanModify: Boolean, read
See also CanView, AdapterType.CanView
Indicates whether the end-user has rights
to modify this field's value.
CanView: Boolean, read
See also CanModify, AdapterType.CanModify
Indicates whether the end-user has rights
to view this field's value.
DisplayLabel: text, read
Suggests a DisplayLabel for this adapter
field.
DisplayStyle: text, read
See also InputStyle, ViewMode, Example17
DisplayStyle suggests how to display a
read-only representation of a field's value.
Server-side script may use the DisplayStyle
to determine how to generate HTML. An adapter field may return one
of the following display styles.
| ‘’ |
Undefined display style |
| ‘Text’ |
Use <p> |
| ‘Image’ |
Use <img>. The Image property of the field
defines the src property. |
| ‘List’ |
Use <UL>. Enumerate the Values property to
to generate each <LI> item. |
The ViewMode property indicates whether to
use the InputStyle or DisplayStyle to generate HTML.
DisplayText: text, read
See also EditText, Example9
Provides text to use when displaying the
adapter field's value for reading only. The value of DisplayText
may include numeric formatting.
DisplayWidth: integer, read
See also MaxLength
Suggests a display width, in characters,
for an adapter field's value.
-1 is returned if the display width is
undefined.
EditText:
text, read
See also DisplayText, Example10
Provides text to use when defining an HTML
input for this adapter field. The value of EditText is typically
unformatted.
Image: AdapterImage, read
See also AdapterImageType, Example12
Provides an object that defines an image
for this adapter field.
Null is returned If the adapter field does
not provide an image.
InputStyle:
text, read
See also DisplayStyle, ViewMode, Example17
Suggests an HTML input style for this
field.
Server-side script may use the InputStyle
to determine how to generate an HTML element. An adapter field may return one
of the following input styles:
| ‘’ |
Undefined input style |
| 'TextInput' |
Use <input
type=”text”> |
| 'PasswordInput' |
Use <input
type=”password”> |
| 'Select' |
Use <select>. Enumerate the ValuesList
property to generate each <option> element. |
| 'SelectMultiple' |
Use <select multiple>. Enumerate the ValuesList
property to generate each <option> element. |
| 'Radio' |
Enumerate the ValuesList property to
generate one or more <input type=”radio”>. |
| 'CheckBox' |
Enumerate the ValuesList property to
generate one or more <input
type=”checkbox”>. |
| 'TextArea' |
Use <textarea>. |
| 'File' |
Use <input
type=”file”> |
The ViewMode property indicates whether to
use the InputStyle or DisplayStyle to generate HTML.
InputName:
text, read
See also Example10
Provides a name for an HTML input element
to edit this adapter field.
Use InputName when generating an HTML
<input>, <select>, or <textarea> element so that
the adapter component will be able to associate between the
name/value pairs in the HTTP request with adapter fields.
MaxLength: integer, read
See also DisplayWidth
Indicates the maximum length in characters
that can be entered into this field.
-1 is returned if the maximum length is not
defined.
Name: text, read
Returns the variable name of the adapter
field.
Required: Boolean, read
Indicates whether a value for this adapter
field is required when submitting a form.
Value: variant, read
See also Values, DisplayText, EditText
Returns a value that can be used in
calculations. For example, use Value when adding two adapter field
values together.
Values: AdapterFieldValues,
read
See also ValuesList, AdapterFieldValuesType, Value, Example13
Returns a list of the field’s values.
The Values property is Null unless this adapter field supports
multiple values. A multiple value field would be used, for example,
to allow the end-user to select multiple values in a select
list.
ValuesList:
AdapterFieldValuesList, read
See also Values, AdapterFieldValuesListType, Example13
Provides a list of choices for this adapter
field. Use ValuesList when generating an HTML select list, check
box group, or radio button group. Each item in ValuesList has a
value and may have a name.
Visible: Boolean, read
Indicates whether this adapter field should
be visible on the HTML page.
ViewMode: text, read
See also DisplayStyle,, InputStyle, Example17
Suggests how to display this adapter field
value on an HTML page.
An adapter field may return one of the
following view modes:
| ‘’ |
Undefined view mode |
| ''Input' |
Generate editable HTML form elements
using <input>, <textarea>, or <select> |
| 'Display' |
Generate read-only HTML using
<p>, <ul>, or <img> |
The ViewMode property indicates whether to
use the InputStyle or DisplayStyle to generate HTML.
Methods
IsEqual(Value): Boolean
See also Example16
Call this function to compare a variable
with an adapter field's value.
AdapterFieldValuesType
See also AdapterFieldType.Values
Provides a list of the field’s
values. Multiple value adapter fields support this property. A
multiple value field would be used, for example, to allow the
end-user to select multiple values in a select list.
Properties
Value: variant,
read
See also ValueField
Returns the Value of the current
enumeration item.
Records: Enumerator, read
See also Example15
Enumerates the records in the list of
Values.
ValueField: AdapterField, read
See also AdapterFieldType, Example15
Returns an adapter field for the current
enumeration item. Use ValueField, for example, to get the
DisplayText for the current enumeration item.
Methods
HasValue(Value):
Boolean
See also Example14
Indicates whether a given value is in the
list of field values. This method is to determine whether to select
an item in an HTML select list or check an item in a group of check
boxes.
AdapterFieldValuesListType
See also AdapterType
Provides a list of possible values for
this adapter field.
Use ValuesList when generating an HTML
select list, check box group, or radio button group. Each item in ValuesList contains
a value and may contain a name.
Properties
Image: AdapterImage,
read
Returns the image of the current
enumeration item.
Null is returned if the item doesn’t
have an image.
Records: Enumerator,
read
Enumerates the records in the list of
Values.
Value: variant,
read
Returns the Value of the current
enumeration item.
ValueField: AdapterField, read
See also AdapterFieldType, Example15
Returns an adapter field for the current
enumeration item. Use ValueField, for example, to get the
DisplayText for the current enumeration item.
ValueName: text,
read
Returns the text name of the current
item.
Blank is returned if the value does not
have a name.
Methods
ImageOfValue(Value):
AdapterImage
Looks up the image associated with this
value.
Null is returned if there is no image.
NameOfValue(Value):
text
Looks up the name associated with this
value.
Blank is returned if the value is not found
of if the value does not have a name.
AdapterHiddenFieldsType
See also AdapterType.HiddenFields, AdapterType.HiddenRecordFields
Provides access to the hidden field
names and values that an adapter requires on HTML forms used to
submit changes.
Properties
Name: text,
read
Returns the name of the hidden field being
enumerated.
Value: text,
read
Returns the string value of the hidden
field being enumerated.
Methods
WriteFields(Response)
See also Example10, Example22
Writes hidden field names and values using
<input type="hidden">.
Call this method to write all of the HTML
hidden fields to an HTML form.
AdapterImageType
See also AdapterFieldType, AdapterActionType
Represents an image that is associated
with an action or a field.
Properties
AsHREF: text,
read
See also Example11 ,
Example12
Provides a URL that can be used to define
an HTML <img> element.
Application
See also AdapterType
The Application object provides access
to information about the application.
Use the
Application object to access fields and actions of the application
adapter, such as the Title field. The Application
object is an Adapter so it can be customized with additional fields
and actions. Fields and
actions that have been added to the application adapter can be
accessed by name as properties of the Application
object.
Properties
Designing:
Boolean, read
See also Example1
Indicates whether the web application is
being designed in the IDE.
Use the Designing flag to conditionally
generate HTML that must be different when in design mode than when
the web application is running.
ModulePath: text,
read
See also QualifyFileName
Identifies the location of the web
application executable.
Use the ModulePath to construct file names
that are in the same directory as the executable.
ModuleFileName: text,
read
See also QualifyFileName
Identifies the fully qualified file name of
the executable.
Title: text, read
See also Example18
Provides the title of the application.
The Title property has the value of
TApplicationAdapter.Title component property. Typically this value is displayed
at the top of HTML pages.
Methods
QualifyFileName(FileName): text
See also Example1
Make a relative filename or directory
reference an absolute reference.
QualifyFileName uses the directory location
of the web application executable to qualify a filename that is not
fully qualified. A
fully qualified filename is returned. If the filename parameter
is fully qualified, the filename is returned without change.
If in design mode, the filename parameter is qualified with the
directory location of the project file.
EndUser
See also AdapterType
The EndUser object provides access to
information about the current end-user.
Use to EndUser object to access fields
and actions of the end-user adapter, such as the DisplayName for
the end-user, the Login action, and Logout action. Fields and
actions that have been added to the enduser adapter can be accessed
by name as properties of the EndUser object.
Properties
DisplayName: text,
read
See also Example19
Provides the name of the end-user.
LoggedIn: Boolean,
read
See also Example19
Indicates whether the end-user is logged
in.
LogInFormAction:
AdapterAction, read
See also Example19, AdapterActionType
Provides the adapter action used to login a
user
LogoutAction:
AdapterAction, read
See also Example19, AdapterActionType
Provides the adapter action used to
logout a user
ModuleType
See also Modules
Adapter components can be referenced by
name as properties of a module. Also use a module to enumerate the
scriptable objects (usually adapters) of a module.
Properties
Name_: text,
read
See also Example20
Identifies the variable name of the
module. This is the name used
to access the module as a property of the Modules
variable.
ClassName_: text,
read
See also Example20
Identifies the VCL class name of the
module.
Objects:
Enumerator
See also Example20
Use Objects to enumerate the scriptable
objects (typically adapters) within a module.
Modules
See also Example2, Example20
Modules provides access to all modules
that have been instantiated or activated to service the current
HTTP request.
To references a particular module use
the module's name as a property of the Modules variable. To enumerate all modules
within the application, create an enumerator using the Modules
object.
Page
See also Example5, PageType
Page provides access to the properties
of the page being generated.
See PageType for a description of the
properties and methods of the Page object.
Pages
See also Example5
Pages provides access to all pages
registered by the application.
To references a particular page use the
page's name as a property of the Pages variable. To enumerate all pages within the
application, create an enumerator using the Pages object.
PageType
See also Page,
Example20
Defines properties and methods of
pages.
Properties
CanView: Boolean,
read
Indicates
whether the end-user has rights to view this page.
A page
registers access rights. CanView compares the rights
registered by the page with the rights granted to the
end-user.
DefaultAction: AdapterAction, read
See also Example6
Identifies the default adapter action
associated with this page.
A default action is typically used when
parameters must be passed to a page. DefaultAction may be Null.
HREF: text, read
See also Example5
Provides a URL that can be used to generate
a hyperlink to this page using the <a> tag.
LoginRequired:
Boolean, read
Indicates whether the end-user must login
before accessing this page.
A page registers a LoginRequired flag. If True then the end-user
will not be permitted to access this page unless logged in.
Name: text,
read
See also Example5
Provides the name of the registered
page.
If the page is published, the
PageDispatcher will generate the page when the page’s name is
a suffix of the HTTP request’s path info.
Published: Boolean, read
See also Example5
Indicates whether the end-user can access
this page by specifying the page name as a suffix to the URL.
A page
registers a published flag. The PageDispatcher will
automatically dispatch published page. Typically the published flag is
used while generating a menu with hyperlinks to pages. Pages that have the published
flag set to False are not listed in the menu.
Title: text, read
See also Example5, Example18
Provides
the title of this page.
The title
is typically displayed to the user.
Producer
See also Response
Use the Producer object to write text
containing transparent tags. The tags will be translated by the
page producer and then written to the HTTP response. If the text
does not contain transparent tags, use the Response object for
better performance.
Properties
Content: text,
read/write
Provides access to the content portion of
the HTTP response.
Use the Content to read or write the entire
content portion of the HTTP response. Setting Content translates
transparent tags. If
not using transparent tags, set Response.Content for better
performance.
Methods
Write(Value)
Appends to the content portion of the HTTP
request with support for transparent tags.
Use the Write method to append to the
content portion of the HTTP request’s content. Write
translates transparent tags. (E.g.; Write('Translate this:
<#MyTag>').
If not using
transparent tags, use Response.Write for better performance.
Request
Provides access to the HTTP request.
Use properties of the Response object to
access information about the HTTP request.
Properties
Host: text,
read
Reports the value of the Host header of the
HTTP request.
Host is the same as TWebRequest.Host.
PathInfo: text, read
Contains the PathInfo portion of the
URL.
PathInfo is the same as the
TWebRequest.InternalPathInfo property.
ScriptName: text,
read
Contains the script name portion of the
URL, which specifies the name of a Web server application.
ScriptName is the same as the
TWebRequest.InternalScriptName property.
Response
See also Producer
Provides access to the HTTP response.
Use the Response object to write to the content portion of the HTTP
response. If writing transparent tags, use the Producer object
instead of the Response object.
Properties
Content: text,
read/write
Provides access to the content portion of
the HTTP response.
Use Content to read or write the entire
content portion of the HTTP response.
Methods
Write(Value)
See also Example5
Appends to the content portion of the HTTP
request.
Use the Write method to append to the
content of the HTTP request’s content. Write does not translate
transparent tags. Use
Producer.Write to write a string containing one or more transparent
tags.
Session
The Session object provides access to
the session id and values.
A session is used to keep track of
information about the end-user for a short period of time.
Properties
SessionID.Value:
text, read/write
Provides access to the id of the
current end-user’s session.
Values(Name):
variant, read
Provides access to values stored
in current end-user’s session.
Example1
Generate a relative path reference to an
image. If in design mode then reference an actual directory. If
running then reference a virtual directory.
See also Application.Designing , Application.QualifyFileName , Request.PathInfo
<%
function PathInfoToRelativePath(S)
{
var R = '';
var L = S.length
I = 0
while (I < L)
{
if (S.charAt(I) == '/')
R = R + '../'
I++
}
return R
}
function QualifyImage(S)
{
if (Application.Designing)
return Application.QualifyFileName("..images" + S); // relative directory
else
return PathInfoToRelativePath(Request.PathInfo) + '../images/' + S; // virtual directory
}
%>
Example2
Declare a variable that references WebModule1:
See also Modules
<% var M = Modules.WebModule1 %>
Example3
Enumerate the instantiated module and
display their variable name and vcl class name in a table:
See also Modules
<table border=1>
<tr><th>Name</th><th>ClassName</th></tr>
<%
var e = new Enumerator(Modules)
for (; !e.atEnd(); e.moveNext())
{
%>
<tr><td><%=e.item().Name_%></td><td><%=e.item()ClassName._%></td></tr>
<%
}
%>
</table>
Example4
Declare a variable that reference the
page named Home. Display Home's title.
See also Pages, Page.Title
<% var P = Pages.Home %>
<p><%= P.Title %></p>
Example5
Enumerate the registered pages and
create a menu displaying hyperlinks to all published pages:
See also Pages, Page.Published, Page.HREF, Response.Write
<table>
<td>
<% e = new Enumerator(Pages)
s = ''
c = 0
for (; !e.atEnd(); e.moveNext())
{
if (e.item().Published)
{
if (c>0) s += ' | '
if (Page.Name != e.item().Name)
s += '<a href="' + e.item().HREF + '">' + e.item().Title + '</a>'
else
s += e.item().Title
c++
}
}
if (c>1) Response.Write(s)
%>
</td>
</table>
Example6
Enumerate the registered pages and
create a menu displaying hyperlinks to DefaultActions.
See also PageType.DefaultAction
<table>
<td>
<% e = new Enumerator(Pages)
s = ''
c = 0
for (; !e.atEnd(); e.moveNext())
{
if (e.item().Published)
{
if (c>0) s += ' | '
if (Page.Name != e.item().Name)
if (e.item().DefaultAction != null)
s += '<a href="' + e.item().DefaultAction.AsHREF + '">' + e.item().Title + '</a>'
else
s += '<a href="' + e.item().HREF + '">' + e.item().Title + '</a>'
else
s += e.item().Title
c++
}
}
if (c>1) Response.Write(s)
%>
</td>
</table>
Example7
Write a list of errors detected by an
adapter.
See also AdapterType.Errors, AdapterErrorsType, Modules, Response.Write
<% {
var e = new Enumerator(Modules.CountryTable.Adapter.Errors)
for (; !e.atEnd(); e.moveNext())
{
Response.Write("<li>" + e.item().Message)
}
e.moveFirst()
} %>
Example8
Enumerate all of the actions of an
adapter and display action property values in a table.
See also AdapterType.Actions, AdapterActionType
<% // Display some properties of an action in a table
function DumpAction(A)
{
%>
<table border="1">
<tr><th COLSPAN=2><%=A.Name%></th>
<tr><th>AsFieldValue:</th><td><%= A.AsFieldValue %></td>
<tr><th>AsHREF:</th><td><%= A.AsHREF %></span>
<tr><th>DisplayLabel:</th><td><%= A.DisplayLabel %></td>
<tr><th>Enabled:</th><td><%= A.Enabled %></td>
<tr><th>CanExecute:</th><td><span class="value"><%= A.CanExecute %></td>
</table>
<%
}
%>
<% // Call the DumpAction function for every action in an adapter
function DumpActions(A)
{
var e = new Enumerator(A)
for (; !e.atEnd(); e.moveNext())
{
DumpAction(e.item())
}
}
%>
<%
// Display properties of actions in the adapter named Adapter1
DumpActions(Adapter1.Actions) %>
Example9
See also AdapterType.Records, AdapterFieldType.DisplayText
Generate an HTML table by enumerating
the records of an adapter.
<%
// Define some variables that reference the adapter and fields that will be used.
vAdapter=Modules.CountryTable.Adapter
vAdapter_Name=vAdapter.Name
vAdapter_Capital=vAdapter.Capital
vAdapter_Continent=vAdapter.Continent
%>
<%
// Function to write column text so that all cells have borders
function WriteColText(t)
{
Response.Write((t!="")?t:" ")
}
%>
<table border="1">
<tr>
<th>Name</th>
<th>Capital</th>
<th>Continent</th>
<%
// Enumerate all the records in the adapter and write the field values.
var e = new Enumerator(vAdapter.Records)
for (; !e.atEnd(); e.moveNext())
{ %>
<tr>
<td><div><% WriteColText(vAdapter_Name.DisplayText) %></div></td>
<td><div><% WriteColText(vAdapter_Capital.DisplayText) %></div></td>
<td><div><% WriteColText(vAdapter_Continent.DisplayText) %></div></td>
</tr>
<%
}
%>
</table>
Example10
See also AdapterActionType.LinkToPage, AdapterActionType.AsFieldValue, AdapterFieldType.InputName, AdapterFieldType.DisplayText, AdapterType.HiddenFields ,
AdapterType.HiddenRecordFields
Generate a HTML form to edit adapter
fields and submit adapter actions.
<%
// Define some variables that reference the adapter, fields, and actions that will be used.
vAdapter=Modules.CountryTable.Adapter
vAdapter_Name=vAdapter.Name
vAdapter_Capital=vAdapter.Capital
vAdapter_Continent=vAdapter.Continent
vAdapter_Apply=vAdapter.Apply
vAdapter_RefreshRow=vAdapter.RefreshRow
// Put the adapter in "Edit" mode unless the mode is already set. If the mode is already
// set then this is probably because an adapter action set the mode. For example, an insert
// row action would put the adapter in "Insert" mode.
if (vAdapter.Mode=="")
vAdapter.Mode="Edit"
%>
<form name="AdapterForm1" method="post">
<!-- This hidden field is used to define the action that is executed when the form is submitted -->
<input type="hidden" name="__act">
<%
// Write out hidden fields defined by the adapter.
if (vAdapter.HiddenFields != null)
{
vAdapter.HiddenFields.WriteFields(Response)
} %>
<% if (vAdapter.HiddenRecordFields != null)
{
vAdapter.HiddenRecordFields.WriteFields(Response)
} %>
<table>
<tr>
<td>
<table>
<tr>
<!-- Write input fields to edit the fields of the adapter -->
<td>Name</td>
<td ><input type="text" size="24" name="<%=vAdapter_Name.InputName%>" value="<%= vAdapter_Name.EditText %>" ></td>
</tr>
<tr>
<td>Capital</td>
<td ><input type="text" size="24" name="<%=vAdapter_Capital.InputName%>" value="<%= vAdapter_Capital.EditText %>" ></td>
</tr>
<tr>
<td>Continent</td>
<td ><input type="text" size="24" name="<%=vAdapter_Continent.InputName%>" value="<%= vAdapter_Continent.EditText %>" ></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<!-- Write submit buttons to execute actions. LinkToPage is used so that this page will be
regenerated after executing an action. -->
<tr>
<td><input type="submit" value="Apply"
onclick="AdapterForm1.__act.value='<%=vAdapter_Apply.LinkToPage(Page.Name).AsFieldValue%>'"></td>
<td><input type="submit" value="Refresh"
onclick="AdapterForm1.__act.value='<%=vAdapter_RefreshRow.LinkToPage(Page.Name).AsFieldValue%>'"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
Example11
Display adapter actions to support
paging. The PrevPage, GotoPage, and NextPage actions are displayed
as hyperlinks. The GotoPage action has an array of commands. The
commands are enumerated to generate a hyperlink to jump to each
page.
See also AdapterActionType.Array, AdapterActionType.AsHREF
<%
// Define some variables for adapter and actions
vAdapter = Modules.WebDataModule1.QueryAdapter
vPrevPage = vAdapter.PrevPage
vGotoPage = vAdapter.GotoPage
vNextPage = vAdapter.NextPage
%>
<!-- Generate a table that will display hyperlinks to move between pages of the adapter -->
<table cellpadding="5">
<tr>
<td>
<%
// Prevpage displays "<<". Only use an anchor tag if the action is enabled
if (vPrevPage.Enabled)
{ %>
<a href="<%=vPrevPage.LinkToPage(Page.Name).AsHREF%>"><<</a>
<%
}
else
{%>
<a><<</a>
<%} %>
<%
// GotoPage has a list of commands. Loop through the list. Only use an anchor tag if the command
// is enabled
if (vGotoPage.Array != null)
{
var e = new Enumerator(vGotoPage.Array)
for (; !e.atEnd(); e.moveNext())
{
%>
<td>
<% if (vGotoPage.Enabled)
{ %>
<a href="<%=vGotoPage.LinkToPage(Page.Name).AsHREF%>"><%=vGotoPage.DisplayLabel%></a>
<% }
else
{ %>
<a><%=vGotoPage.DisplayLabel%></a>
<% }
%>
</td>
<%
}
}
%>
<td>
<%
// NextPage displays ">>". Only use an anchor tag if the action is enabled
if (vNextPage.Enabled)
{ %>
<a href="<%=vNextPage.LinkToPage(Page.Name).AsHREF%>">>></a>
<%
}
else
{%>
<a>>></a>
<%} %>
</td>
</table>
Example12
Display an adapter field's image.
See also AdapterFieldType.Image
<%
// Declare variables for adapter and field
vAdapter=Modules.WebDataModule3.DataSetAdapter1
vGraphic=vAdapter.Graphic
%>
<!-- Display the adapter field as an image. -->
<img src="<%=(vGraphic.Image!=null) ? vGraphic.Image.AsHREF : ''%>" alt="<%=vGraphic.DisplayText%>">
Example13
Write an adapter field with HTML
<select> and <option> elements.
See also AdapterFieldType.Values, AdapterFieldType.ValuesList
<%
// Return an object that defines HTML select options for an adapter field.
// The returned object has the following elements:
//
// text - string containing the <option> elements.
// count - the number of <option> elements.
// multiple - string containing the either 'multiple' or ''. Use this value as an attribute of the
// <select> element.
//
// Use as follows:
// obj=SelOptions(f)
// Response.Write('<select size="' + obj.count + '" name="' + f.InputName + '" ' + obj.multiple + '>' +
// obj.text + '</select>')
function SelOptions(f)
{
var s=''
var v=''
var n=''
var c=0
if (f.ValuesList != null)
{
var e = new Enumerator(f.ValuesList.Records)
for (; !e.atEnd(); e.moveNext())
{
s+= '<option'
v = f.ValuesList.Value;
var selected
if (f.Values == null)
selected = f.IsEqual(v)
else
selected = f.Values.HasValue(v)
if (selected)
s += ' selected'
n = f.ValuesList.ValueName;
if (n=='')
{
n = v
v = ''
}
if (v!='') s += ' value="' + v + '"'
s += '>' + n + '</option>rn'
c++
}
e.moveFirst()
}
r = new Object;
r.text = s
r.count = c
r.multiple = (f.Values == null) ? '' : 'multiple'
return r;
}
%>
<%
// Generate HTML select options for an adapter field
function WriteSelectOptions(f)
{
obj=SelOptions(f)
%>
<select size="<%=obj.count%>" name="<%=f.InputName%>" <%=obj.multiple%> >
<%=obj.text%>
</select>
<%
}
%>
Example14
Write an adapter field as group of
<input type="checkbox"> elements.
See also AdapterFieldType.Values, AdapterFieldType.ValuesList
<%
// Return an object that defines HTML checkboxes for an adapter field.
// The returned object has the following elements:
//
// text - string containing the <input type=checkbox> elements.
// count - the number of <option> elements.
//
// Use as follows to define a checkbox group with three columns and no additional attributes:
// obj=CheckBoxGroup(f, 3, '')
// Response.Write(obj.text)
//
function CheckBoxGroup(f,cols,attr)
{
var s=''
var v=''
var n=''
var c=0;
var nm=f.InputName
if (f.ValuesList == null)
{
s+= '<input type="checkbox"'
if (f.IsEqual(true)) s+= ' checked'
s += ' value="true"' + ' name="' + nm + '"'
if (attr!='') s+= ' ' + attr
s += '></input>rn'
c = 1
}
else
{
s += '<table><tr>'
var e = new Enumerator(f.ValuesList.Records)
for (; !e.atEnd(); e.moveNext())
{
if (c % cols == 0 && c != 0) s += '</tr><tr>'
s+= '<td><input type="checkbox"'
v = f.ValuesList.Value;
var checked
if (f.Values == null)
checked = (f.IsEqual(v))
else
checked = f.Values.HasValue(v)
if (checked)
s+= ' checked'
n = f.ValuesList.ValueName;
if (n=='')
n = v
s += ' value="' + v + '"' + ' name="' + nm + '"'
if (attr!='') s+= ' ' + attr
s += '>' + n + '</input></td>rn'
c++
}
e.moveFirst()
s += '</tr></table>'
}
r = new Object;
r.text = s
r.count = c
return r;
}
%>
<%
// Write an adapter field as a check box group
function WriteCheckBoxGroup(f, cols, attr)
{
obj=CheckBoxGroup(f, cols, attr)
Response.Write(obj.text);
}
%>
Example15
Write an adapter field as a list of read
only values using <ul> and <li> elements.
See also AdapterFieldType.Values, AdapterFieldValuesType,
AdapterFieldType.ValuesList
<%
// Return an object that defines HTML list values for an adapter field.
// The returned object has the following elements:
//
// text - string containing the <li> elements.
// count - the number of elements.
//
// text will be blank and count will be zero if the adapter field does not
// support multiple values.
//
// Use as follows to define a displays a read only list of this an adapter
// fields values.
// obj=ListValues(f)
// Response.Write('<ul>' + obj.text + '</ul'>')
//
function ListValues(f)
{
var s=''
var v=''
var n=''
var c=0;
r = new Object;
if (f.Values != null)
{
var e = new Enumerator(f.Values.Records)
for (; !e.atEnd(); e.moveNext())
{
s+= '<li>'
s += f.Values.ValueField.DisplayText;
s += '</li>'
c++
}
e.moveFirst()
}
r.text = s
r.count = c
return r;
}
%>
<%
// Write an adapter field as a list of read-only values
function WriteListValues(f)
{
obj=ListValues(f)
%>
<ul><%=obj.text%></ul>
<%
}
%>
Example16
Write an adapter field as a group of
<input type="radio"> elements.
See also AdapterFieldValuesListType, AdapterFieldType.Values, AdapterFieldType.ValuesList
<%
// Return an object that defines HTML radiobuttons for an adapter field.
// The returned object has the following elements:
//
// text - string containing the <input type=radio> elements.
// count - the number of elements.
//
// Use as follows to define a radiobutton group with three columns and no additional attributes:
// obj=RadioGroup(f, 3, '')
// Response.Write(obj.text)
//
function RadioGroup(f,cols,attr)
{
var s=''
var v=''
var n=''
var c=0;
var nm=f.InputName
if (f.ValuesList == null)
{
s+= '<input type="radio"'
if (f.IsEqual(true)) s+= ' checked'
s += ' value="true"' + ' name="' + nm + '"'
if (attr!='') s+= ' ' + attr
s += '></input>rn'
c = 1
}
else
{
s += '<table><tr>'
var e = new Enumerator(f.ValuesList.Records)
for (; !e.atEnd(); e.moveNext())
{
if (c % cols == 0 && c != 0) s += '</tr><tr>'
s+= '<td><input type="radio"'
v = f.ValuesList.Value;
var checked
if (f.Values == null)
checked = (f.IsEqual(v))
else
checked = f.Values.HasValue(v)
if (checked)
s+= ' checked'
n = f.ValuesList.ValueName;
if (n=='')
{
n = v
}
s += ' value="' + v + '"' + ' name="' + nm + '"'
if (attr!='') s+= ' ' + attr
s += '>' + n + '</input></td>rn'
c++
}
e.moveFirst()
s += '</tr></table>'
}
r = new Object;
r.text = s
r.count = c
return r;
}
%>
<%
// Write an adapter field as a radiobutton group
function WriteRadioGroup(f, cols, attr)
{
obj=RadioGroup(f, cols, attr)
Response.Write(obj.text);
}
%>
Example17
Generates HTML for an adapter field
based on the field's InputStyle, DisplayStyle, and ViewMode
property values.
See also AdapterFieldType.DisplayStyle, AdapterFieldType.ViewMode, AdapterFieldType.InputStyle
<%
// Write HTML for an adapter field using the InputStyle, DisplayStyle, and
// ViewMode properties.
function WriteField(f)
{
Mode = f.ViewMode
if (Mode == 'Input')
{
Style = f.InputStyle
if (Style == 'SelectMultiple' || Style == 'Select')
WriteSelectOptions(f)
else if (Style == 'CheckBox')
WriteCheckBoxGroup(f, 2, '')
else if (Style == 'Radio')
WriteRadioGroup(f, 2, '')
else if (Style == 'TextArea')
{
%>
<textarea wrap=OFF name="<%=f.InputName%>"><%= f.EditText %></textarea>
<%
}
else if (Style == 'PasswordInput')
{
%>
<input type="password" name="<%=f.InputName%>"/>
<%
}
else if (Style == 'File')
{
%>
<input type="file" name="<%=f.InputName%>"/>
<%
}
else
{
%>
<input type="input" name="<%=f.InputName%>" value="<%= f.EditText %>"/>
<%
}
}
else
{
Style = f.DisplayStyle
if (Style == 'List')
WriteListValues(f)
else if (Style == 'Image')
{
%>
<img src="<%=(f.Image!=null) ? f.Image.AsHREF : ''%>" alt="<%=f.DisplayText%>">
<% }
else
Response.Write('<p>' + f.DisplayText + '</p>')
}
}
%>
Example18
Use properties of the Application object
and Page object to generate a page heading.
See also Page,
Application.Title
<html>
<head>
<title>
<%= Page.Title %>
</title>
</head>
<body>
<h1><%= Application.Title %></h1>
<h2><%= Page.Title %></h2>
Example19
Use properties of the EndUser object to
display the end-user's name, login command, and logout command.
See also EndUser
<% if (EndUser.Logout != null)
{
if (EndUser.DisplayName != '')
{
%>
<h1>Welcome <%=EndUser.DisplayName %></h1>
<% }
if (EndUser.Logout.Enabled) {
%>
<a href="<%=EndUser.Logout.AsHREF%>">Logout</a>
<% }
if (EndUser.LoginForm.Enabled) {
%>
<a href=<%=EndUser.LoginForm.AsHREF%>>Login</a>
<% }
}
%>
Example20
List the scriptable objects in a
module.
See also Module
<%
// Write an HTML table list the name and vcl classname of all scriptable objects in a module
function ListModuleObjects(m)
{
%>
<p></p>
<table border="1">
<tr>
<th colspan="2"><%=m.Name_ + ': ' + m.ClassName_%></th>
</tr>
<%
var e = new Enumerator(m.Objects)
for (; !e.atEnd(); e.moveNext())
{
%>
<tr>
<td>
<%= e.item().Name_ + ': ' + e.item().ClassName_ %>
</td>
</tr>
<%
}
%>
</table>
<%
}
%>
Example21
Generate HTML for an adapter action
based on the actions's DisplayStyle property.
See also AdapterlActionType.DisplayStyle, AdapterlActionType.Enabled,
<%
// Write HTML for an adapter action using the DisplayStyle property.
//
// a - action
// cap - caption. If blank the action's display label is used.
// fm - name of the HTML form
// p - page name to goto after action execution. If blank, the current page is used.
//
// Note that this function does not use the action's Array property. Is is assumed that
// the action has a single command.
//
function WriteAction(a, cap, fm, p)
{
if (cap == '')
cap = a.DisplayLabel
if (p == '')
p = Page.Name
Style = a.DisplayStyle
if (Style == 'Anchor')
{
if (a.Enabled)
{
// Do not use the href property. Instead, submit the form so that HTML form fields are part of the HTTP request.
%>
<a href=""
onclick="<%=fm%>.__act.value='<%=a.LinkToPage(p).AsFieldValue%>';<%=fm%>.submit();return false;"><%=cap%></a>
<%
}
else
{
%>
<a><%=cap%></a>
<%
}
}
else
{
%>
<input type="submit" value="<%= cap%>" onclick="<%=fm%>.__act.value='<%=a.LinkToPage(p).AsFieldValue%>'">
<%
}
}
%>
Example22
Generate an HTML table to update
multiple detail records.
See also AdapterType.HiddenFields, AdapterType.HiddenRecordFields, AdapterType.Mode
<%
vItemsAdapter=Modules.DM.ItemsAdapter
vOrdersAdapter=Modules.DM.OrdersAdapter
vOrderNo=vOrdersAdapter.OrderNo
vCustNo=vOrdersAdapter.CustNo
vPrevRow=vOrdersAdapter.PrevRow
vNextRow=vOrdersAdapter.NextRow
vRefreshRow=vOrdersAdapter.RefreshRow
vApply=vOrdersAdapter.Apply
vItemNo=vItemsAdapter.ItemNo
vPartNo=vItemsAdapter.PartNo
vDiscount=vItemsAdapter.Discount
vQty=vItemsAdapter.Qty
%>
<!-- Use two adapters to update multiple detail records.
The orders adapter is associated with the master dataset.
The items adapter is associated with the detail dataset.
Each row in a grid displays values from the items adapter. One
column display an <input> element for editing Qty. The apply button
updates the Qty value in each detail record.
<!-- Display the order number and customer number values -->
<h2>OrderNo: <%= vOrderNo.DisplayText %></h2>
<h2>CustNo: <% vCustNo.DisplayText %></h2>
<%
// Put the items adapter in edit mode because this form updates
// the Qty field.
vItemsAdapter.Mode = 'Edit'
%>
<form name="AdapterForm1" method="post">
<!-- Define a hidden field for submitted the action name and parameters -->
<input type="hidden" name="__act">
<%
// Write hidden fields containing state information about the
// orders adapter and items adapter.
if (vOrdersAdapter.HiddenFields != null)
vOrdersAdapter.HiddenFields.WriteFields(Response)
if (vItemsAdapter.HiddenFields != null)
vItemsAdapter.HiddenFields.WriteFields(Response)
// Write hidden fields containing state information about the current
// record of the orders adapter.
if (vOrdersAdapter.HiddenRecordFields != null)
vOrdersAdapter.HiddenRecordFields.WriteFields(Response)%>
<table border="1">
<tr>
<th>ItemNo</th>
<th>PartNo</th>
<th>Discount</th>
<th>Qty</th>
</tr>
<%
var e = new Enumerator(vItemsAdapter.Records)
for (; !e.atEnd(); e.moveNext())
{ %>
<tr>
<td><%=vItemNo.DisplayText%></td>
<td><%=vPartNo.DisplayText%></td>
<td><%=vDiscount.DisplayText%></td>
<td><input type="text" name="<%=vQty.InputName%>" value="<%= vQty.EditText %>" ></td>
</tr>
<%
// Write hidden fields containing state information about each record of the
// items adapter. This is needed by the items adapter when updating the Qty field.
if (vItemsAdapter.HiddenRecordFields != null)
vItemsAdapter.HiddenRecordFields.WriteFields(Response)
}
%>
</table>
<p></p>
<table>
<td><input type="submit" value="Prev Order"
onclick="AdapterForm1.__act.value='<%=vPrevRow.LinkToPage(Page.Name).AsFieldValue%>'"></td>
<td><input type="submit" value="Next Order"
onclick="AdapterForm1.__act.value='<%=vNextRow.LinkToPage(Page.Name).AsFieldValue%>'"></td>
<td><input type="submit" value="Refresh"
onclick="AdapterForm1.__act.value='<%=vRefreshRow.LinkToPage(Page.Name).AsFieldValue%>'"></td>
<td><input type="submit" value="Apply"
onclick="AdapterForm1.__act.value='<%=vApply.LinkToPage(Page.Name).AsFieldValue%>'"></td>
</table>
</form>