<datapath>
The binder between data and nodes.

JavaScript: lz.datapath
extends <datapointer> » <node> » lz.Eventable »

Usage

<view>
   <datapath xpath="xpath" sortorder="ascending"/>
 </view>
<view datapath="xpath" />

Datapaths are used to merge data hierarchies with the hierarchy of an OpenLaszlo application. This is done using the the XPath syntax supported by lz.datapointer. 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 lz.ReplicationManager takes over the view's spot in its parent.

When a node is replicated, an LzReplicationManager takes it's place, and an onclones will be sent when the node's clones are updated.

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 10. 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 datapath="name()"/>
       <text datapath="text()"/>
       <text datapath="@temp"/>
     </view>
   </view>
 </canvas>

Attributes

Name (CSS property) Type (tag) Type (js) Default Category
axis 'x'|'y' String 'y' initialize-only
  The direction in which the replicated elements will be layed out.
[Note] Note
This attribute is only available if replication is set to either "lazy" or "resize".
pooling boolean Boolean false initialize-only
  This attribute applies to datapaths which match multiple nodes and force replication. If pooling is true, views that are data-bound to this datapath are recycled if the dataset changes. Otherwise, views are deleted when the data nodes they are bound to disappear, and created when new data nodes match the datapath. See the section on Pooling in the Guide for information about the use of this attribute.
replication 'normal' | 'lazy' | 'resize' String 'normal' initialize-only
  Determines whether to use normal or lazy replication, if the datapath matches more than one node. See the section on Replication in the Guide for information about the use of this attribute.
[Note] Note
The choice of replication style implies a choice of replication manager. Each replication manager may have additional attributes which are specified as attributes of the datapath. For example, lz.LazyReplicationManager takes axis and spacing attributes. See the documentaion for the corresponding replication manager for detailed information on these additional attributes.
sortorder string String|Function   read/write
  The order to use to sort the dataset if replication occurs. One of "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, use setAttribute('sortorder', ...).
sortpath string String   read/write
  An XPath to use to obtain the sort key for sorting if replication occurs. To change this attribute, use .setAttribute('sortpath', ...),
spacing number Number 0 initialize-only
  The spacing (in pixels) between replicated views.
[Note] Note
This attribute is only available if replication is set to either "lazy" or "resize".

Attributes inherited from <datapointer>

context, p, rerunxpath, xpath

Methods

setNodes()
datapath.setNodes(nodes : Array);
Normally, replication is started when a datapath xpath binding returns multiple nodes. This function overides that behavior and forces replication, and replicates over the list of nodes supplied to this function. Note that once this function is called, the replication manager is no longer actively bound to the data it replicates over by its xpath (if it had one); henceforth the replication set can *only* be controlled by calling setNodes.
Parameter Name Type Description
nodes Array A list of LzDataElements to replicate over.

setSelected()
datapath.setSelected(torf);
Sets the selection state of the datapath, used by dataselectionmanager.lzx
Parameter Name Type Description
torf    

updateData()
datapath.updateData();
This method is used to transfer any values that may have been edited in a datamapped UI control back to the dataset. If the current datapath's 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 returns a non-undefined value, 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.

Methods inherited from lz.Eventable

destroy, setAttribute

Events

Events inherited from <datapointer>

onerror, ontimeout

Events inherited from <node>

onconstruct, ondata, oninit

Events inherited from lz.Eventable

ondestroy