Datapaths are used to merge data hierarchies with the hierarchy of an
OpenLaszlo application. This is done using the the XPath syntax supported
by LzDatapointer
. When a node is given a
datapath
attribute, a datapath with
the given value as its XPath is created. If the datapath retrieves a
node (i.e. it doesn't terminate in an attribute getter or a
()
operator) then the node is mapped to that data context
and all child nodes will implicitly share the datacontext, but no
further action is taken. If the datapath retrieves data, rather than
just a node, a few extra things happen. First, the node's
data
property is set and the node's
ondata
event is sent. Second, the node's
applyData
method is called with the data as the
argument. In cases where a datapath matches more than one data node,
the view with the matching datapath is replicated once for each data
node that matches, and a LzReplicationManager takes over
the view's spot in its parent.
A node can only have one datapath, and datapaths always have the name
datapath
. Additional options available on datapath such
as pooling and
replication are specified
by writing the datapath
tag as a separate node.
Example 6. Mapping data to views using datapaths
<canvas height="120"> <dataset name="testdata"> <Monday temp="Hi 48"> Partly Cloudly </Monday> <Tuesday temp="Hi 60"> Showers Likely </Tuesday> <Wednesday temp="Hi 63"> Chance Showers </Wednesday> <Thursday temp="Hi 58"> Mostly Sunny </Thursday> <Friday temp="Hi 50"> Clear and Cold </Friday> </dataset> <simplelayout spacing="5"/> <view datapath="testdata:/*"> <view> <simplelayout axis="x"/> <text /> <text /> <text /> </view> </view> </canvas>
Properties (5)
ascending
or descending
to use
built in dictionary sort, or a function which compares
two strings and returns 1
if the strings
are in order, 0
if they are the same, and
-1
if they are out of order. To change this
attribute, call the setOrder or setComparator method.
Methods (4)
xpath
ends in a terminal selector
(an attribute, text()
, or name()
expression), then the datapath attempts to call its parent's
updateData
method. If this method is defined, the
datapath sets the data element's attribute, text, or name,
respectively, to updateData
's return value. The
method then calls any other updateData
on any
datapaths which depend on this one for context.
In short, to make datamapping work both ways for a given UI
control, define a updateData
method that returns
the value for the data mapped to the node. This is already done
for the base LzInputText
class, but not
for any other LFC classes.
Copyright © 2002-2007 Laszlo Systems, Inc. All Rights Reserved. Unauthorized use, duplication or distribution is strictly prohibited. This is the proprietary information of Laszlo Systems, Inc. Use is subject to license terms.