PDA

View Full Version : Selection Manager for shared data in lazy replication


mjessup
03-06-2009, 11:17 AM
I have data which is being shared across a couple of views using lazy replication. I have deduced that (with the way I am doing it) the selection manager has problems when a node of data is being replicated in two places. Some example code:


<canvas debug="true" width="100%" height="400">
<simplelayout axis="y" />
<view>
<simplelayout axis="x" />
<list id="list1" multiselect="true" dataoption="lazy" width="200" height="200">
<textlistitem name="item" text="$path{'@txt'}">
<datapath replication="lazy" />
</textlistitem>
</list>

<list id="list2" multiselect="true" dataoption="lazy" width="200" height="200">
<textlistitem name="item" text="$path{'@txt'}">
<datapath replication="lazy" />
</textlistitem>
</list>
</view>

<button text="Change">
<handler name="onclick"><![CDATA[
var d = new Array();
for(var i=d.length;i<20;i++)
d.push(new LzDataElement('Node',
{'txt': 'item '+Math.random()}));
list1.item.datapath.setNodes(d);
list2.item.datapath.setNodes(d.slice(10));
]]></handler>
</button>

</canvas>


To replicate the problem click the button to populate the lists with some data. Note it creates 20 elements, all of which go to list 1 and the last 10 of which go to list 2 (done to prove that passing the same/a different array to the datapath isn't the problem). Now two ways in which the selection manager "fails". First select any item in list 2, now scroll down in list 1 and you will see it is selected (not necessarily bad, but unexpected, plus no onselect fired by list 1). Now select an item in list 1 also appearing in list 2 which you can see. Note the item in list 2 is not selected. Attempt to select the item in list 2 and it will "refuse" to be selected (though if you shift-select it will). And if you then unselect list 2, list 1 remains selected, which may be desired, but is inconsistent with the first example.

So my question is as follows. Is there a way in which the same data elements can be shared by different objects using lazy replication and have the selection manager behave as I expect (treating each replicated item independently), or at least in a consistent manner (i.e. selecting/deselecting all replicated views attached to the same data node). I looked around and the closest thing I found sounded like I may need to override the selection manager of the lists? I also checked JIRA but didn't notice anything similar to this, so not sure if I may have discovered a new bug.

I am doing this using LPS4.1.1 and the problem occurs both in SWF8 and DHTML.

pugmaster
03-06-2009, 12:25 PM
I'm not quite sure what you're attempting to do. But when using lazy replication it is necessary to use the dataselectionmanager. In this example from Laszlo in Action, the ResizeReplicationManager extends the LazyReplicationManager:


<canvas>
<dataset name="numbers">
<num>1</num><num>2</num><num>3</num><num>4</num>
<num>5</num><num>6</num><num>7</num><num>8</num><num>9</num>
</dataset>
<view height="100" width="100" clip="true">
<view bgcolor="0xBBBBBB">
<dataselectionmanager name="selector" toggle="true"/>
<text datapath="numbers:/num/text()"
onclick="parent.selector.select(this)">
<datapath replication="resize" spacing="1"/>
<method name="setSelected" args="selected">
if (selected) {
this.setAttribute("bgcolor", 0xCCCCCC);
this.setHeight(40);
this.setAttribute("fontsize", "16"); }
else {
this.setAttribute("bgcolor", 0xBBBBBB);
this.setHeight(15);
this.setAttribute("fontsize", "11"); }
</method>
</text>
</view>
<scrollbar/>
</view>
</canvas>



- Norman Klein
Author: Laszlo in Action

senshi
03-07-2009, 07:17 AM
From lz.dataselectionmanager - reference (http://openlaszlo.org/lps4.2/docs/reference/lz.dataselectionmanager.html):

With lazy replication you must use a lz.dataselectionmanager instead of a lz.selectionmanager. The lz.dataselectionmanager will operate on the data itself, instead of on the views (which may not be present if the data has scrolled out of view). For each dataset you are controlling, you can have only one lz.dataselectionmanager operating on it.