Name
dataset (LzDataset) — An in-memory xml-style data hierarchy.
Description
A dataset
tag defines a
local dataset. The name of the dataset is used in the datapath
attribute of a view.
The src
attribute of the dataset
element specifies whether the data is compiled into the
application or fetched at runtime:
- If the src attribute is a URL, the value of
the dataset is the XML data that a request to the URL named by the
src attribute returns when the application is run.
- If the src
attribute is a pathname, the value of the dataset is the content of
the XML file that the pathname refers to, and is compiled into the
application.
- If the src attribute is not present, the value of the
dataset is the content of the
dataset
element.
All data in an OpenLazlo application is contained within one or more datasets. A given dataset usually represents a single
conceptual set that may or may not be modified or reloaded during the execution of the application.
The data within a dataset is accessed using a datapointer
or a instance of one of its subclasses.
Datasets can represent
- local data (i.e. data which is static after compile time), or
- http-data (data which is returned as XML over HTTP)
If a dataset is not explictly contained within in a ???, it will make an instance of datasource and be contained inside that.
A dataset can be populated or re-poplulated at runtime by calling doRequest
on the dataset. The result of the request is then returned to the application and the dataset's ondata event is run. Any datapointer (LzDatapointer) that is bound to the dataset will also run its ondata event at this time as well.
See the Developers's Guide for more discussion of data and datasets.
Datasets in SOLO applications. Datasets are implemented differently in proxied and SOLO applications, with slight differences in functionality. For example,
in SOLO applications in the SWF7 and SWF8 runtime is it not possible to retrieve http response headers. Also, white space
may be handled differently. See the Developer's Guide.
The example below makes a request of the cgi script on Laszlo's website that serves up weather information in xml form.
Example 8. Making a request using a dataset
<canvas height="250" width="800" debug="true">
<debug y="100"/>
<dataset type="http" name="weatherdata"
src="http://www.laszlosystems.com/cgi-pub/weather.cgi"/>
<view>
<inputtext width="90" name="t">zip</inputtext>
<button> submit
<handler name="onclick"> var d = canvas.datasets.weatherdata;
Debug.write("sending request for weather data.");
d.setQueryString({zip : parent.t.getText()});
d.doRequest();
</handler>
</button>
<datapointer xpath="weatherdata:/weather">
<handler name="ondata">
var duplicate_pointer = this.dupePointer();
duplicate_pointer.selectChild();
while (duplicate_pointer.selectNext()){
Debug.write(duplicate_pointer.serialize());
}
</handler>
</datapointer>
<simplelayout axis="x"/>
</view>
</canvas>
In addition to any fields documented in the section below, these fields are also available:
String querystring
: A string to be appended to the request that
the dataset
makes.
Details
Static Properties (1)
-
anonDatasourceNum
-
static public var anonDatasourceNum = 0.0;
Initial Attributes (5)
Initial Attributes are given as attributes in LZX but are not generally available as properties in JavaScript.
-
port
-
<attribute name="port" type="deprecated" />
-
querytype
-
<attribute name="querytype" />
-
secureport
-
<attribute name="secureport" />
-
src
-
-
timeout
-
<attribute name="timeout" />
Properties (13)
-
acceptencodings
-
<attribute name="acceptencodings" type="boolean" />
public var acceptencodings : Boolean = false;
When true, the server will accept
encoded responses for this request.
Encoded responses require more work for the LPS (encoding the
response) and client (decoding the response) in trade for lower
network bandwidth usage.
-
autorequest
-
<attribute name="autorequest" />
public var autorequest = false;
-
cacheable
-
<attribute name="cacheable" type="boolean" />
public var cacheable : Boolean = false;
When true, the server will attempt to cache
response (defaults to false). There are security concerns
when this field is true. When this field is true, you will usually
want the getresponseheaders field to be false.
-
getresponseheaders
-
<attribute name="getresponseheaders" type="boolean" />
public var getresponseheaders : Boolean = false;
When true, the server will encode and
send the HTTP response headers along with the data (defaults to false).
This does not work for SOLO applications; in SOLO applications the call returns empty.
-
headers
-
<attribute name="headers" />
public var headers = null;
-
nodeType
-
<attribute name="nodeType" />
-
nsprefix
-
<attribute name="nsprefix" type="boolean" />
public var nsprefix : Boolean = false;
When true, the server will preserve namespace prefixes
on data node names and attribute names
-
params
-
<attribute name="params" type="lzParam" />
public var params : LzParam = null;
An LzParams object which holds query key-value pairs.
-
proxied
-
<attribute name="proxied" />
public var proxied = null;
-
querystring
-
<attribute name="querystring" type="string" />
public var querystring : String = null;
A string to be appended to the request that
the dataset makes.
-
responseheaders
-
<attribute name="responseheaders" />
public var responseheaders = null;
-
timeout
-
<attribute name="timeout" />
public var timeout = 30000;
-
trimwhitespace
-
<attribute name="trimwhitespace" type="boolean" />
public final var trimwhitespace : Boolean = false;
When true, the server will trim
whitespace in the XML data (defaults to false).
Setters (2)
Setters for virtual properties, to be used with setAttribute. A setter may or may not have a corresponding getter method;
consult the Methods list in this section.
-
request
-
src
-
The source for requests made by this dataset.
Methods (22)
-
abort()
-
-
clearRequestHeaderParams()
-
<method name="clearRequestHeaderParams" />
protected function clearRequestHeaderParams();
Clears any request header parameters
-
doRequest()
-
<method name="doRequest" />
public function doRequest();
Does a request immediately using the current values. If autorequest is true,
this method is called automatically when values change.
-
getAllResponseHeaders()
-
<method name="getAllResponseHeaders" />
public function getAllResponseHeaders() : LzParam;
Returns all response headers as an object of name/value pairs, or false
if there were none.
-
getErrorString()
-
<method name="getErrorString" />
public function getErrorString() : String;
Returns an error string if there was an error, or false if there was none.
-
getLoadTime()
-
<method name="getLoadTime" />
public function getLoadTime() : Int;
Returns the number of miliseconds it took to load the dataset's request
-
getParams()
-
<method name="getParams" />
public function getParams() : LzParam;
Returns an LzParams object holding any set request parameters for the
dataset.
-
getPointer()
-
<method name="getPointer" />
public function getPointer() : LzDatapointer;
Returns a datapointer pointing to the root of the dataset.
-
getQueryString()
-
<method name="getQueryString" />
public function getQueryString() : String;
Returns the querystring attribute of the dataset, if there is one
-
getRequestHeaderParams()
-
<method name="getRequestHeaderParams" />
public function getRequestHeaderParams() : LzParam;
Retrieves the LzParam object which represents the headers sent with
the dataset's last request
-
getResponseHeader()
-
<method name="getResponseHeader" args="name" />
public function getResponseHeader(name : String) : String;
Returns the value for the specified response header, or false if there
was no header with that name. If name is omitted, all response headers
are returned as an object of name/value pairs.
-
getSrc()
-
public function getSrc() : String;
Return the src attribute of the dataset, if one was given.
-
getStatusCode()
-
<method name="getStatusCode" />
public function getStatusCode();
Returns the status of the dataset's request. Always returns 200 since the
server will respond with an error if the request fails.
-
setHeader()
-
<method name="setHeader" args="k, val" />
public function setHeader(k : String, val : String);
Sets a header for the next request
-
setProxyRequests()
-
<method name="setProxyRequests" args="val" />
public function setProxyRequests(val : String);
Sets whether or not the dataset makes its request directly to the target server
or via the LPS server proxy.
-
setQueryParam()
-
<method name="setQueryParam" args="key, val" />
public function setQueryParam(key : String, val : String);
Sets a named query parameter to the given value. The query parameters are
sent with every request. The key 'lzpostbody' has a specific interpretation,
see setQueryType() for details.
-
setQueryParams()
-
<method name="setQueryParams" args="o" />
public function setQueryParams(o : Object);
Sets multiple query parameters from using the keys in the argument as keys
and the values of those keys as values. This method can also be used to
clear the query params, by passing null to it.
-
setQueryString()
-
<method name="setQueryString" args="s" />
public function setQueryString(s : String);
Sets the querystring parameter of the dataset to the given
string. The dataset's querystring will be pre-pended to any request made
for the dataset.
-
setQueryType()
-
<method name="setQueryType" args="reqtype" />
public function setQueryType(reqtype : Sring);
Sets the query type of for the datasource to one of "POST" or "GET"
by calling the method of the same name on this dataset's datasource.
Note that this controls how the LPS server makes a request of the backend, as well
as how the client communicates with the LPS
-
setRequest()
-
<method name="setRequest" args="b" />
public function setRequest(b : Boolean);
Sets whether or not the dataset makes its request upon initialization
-
setSrc()
-
<method name="setSrc" args="src" />
public function setSrc(src : String);
Sets the src attribute of the dataset's datasource.
-
setURL()
-
<method name="setURL" args="src" />
public function setURL(src);
Events (3)
-
ondata
-
<attribute name="ondata" />
-
onerror
-
<attribute name="onerror" />
Sent when the dataset's request results in an error.
-
ontimeout
-
<attribute name="ontimeout" />
Sent when the request made by the dataset times out.
Prototype Properties (1)
-
request
-
<attribute name="request" />
LZX Synopsis
<class name="
LzDataset" extends="
LzNode
">
<attribute name="
cacheable
" type="
boolean" />
<attribute name="
nsprefix
" type="
boolean" />
<attribute name="
params
" type="
lzParam" />
<method name="
abort
" />
<method name="
setSrc
" args="
src" />
<method name="
setURL
" args="
src" />
</class>
JavaScript Synopsis
public
LzDataset extends
LzNode
{
public var
params
:
LzParam = null;
prototype public function
abort
();
prototype public function
getParams
() :
LzParam;
prototype public function
getPointer
() :
LzDatapointer;
prototype public function
getSrc
() :
String;
prototype public event
ondata
;
prototype public function
setHeader
(
k : String,
val : String);
prototype public function
setQueryParam
(
key : String,
val : String);
prototype public function
setRequest
(
b : Boolean);
prototype public function
setSrc
(
src : String);
prototype public function
setURL
(
src);
}