PDA

View Full Version : Phantom replicated subviews


sfarrow
07-21-2003, 08:26 AM
I am experiencing some unexpected behaviour with replication. In the example below, my dataset has a number of blue elements and within each there are zero or more green elements and zero or more red elements.

By setting blue view containing a red and a green view and letting LzReplicationManager do its stuff, I am getting more subviews than I expect. In the case where a red or green element is not present in the blue element, I still get a subview for it.

In the project that I am working on, I have an event handler for onaddsubview. If I add a green element to a blue element which does not have a green element, I do not get the onaddsubview event. Instead it simply uses the "phantom" subview it had previously created.

In this example below, clicking on a blue view dumps information about its subviews.


<canvas debug="true">
<dataset name="myds">
<blue id="One">
<green id="G1"/>
</blue>
<blue id="Two">
<green id="G1"/>
<red id="R1"/>
</blue>
<blue id="Three">
<red id="R1"/>
</blue>
<blue id="Four">
</blue>
</dataset>

<view datapath="myds:/blue" clickable="true">
<method event="onclick">
for(i in this.subviews) {
Debug.write(" subviews["+i+"]: " + this.subviews[i]);
Debug.write(" subviews["+i+"].height: " + this.subviews[i].height);
Debug.write(" subviews["+i+"].data: " + this.subviews[i].datapath.serialize());
}
</method>
<text datapath="@id" bgcolor="blue"/>
<view datapath="green" height="15" bgcolor="green">
<text datapath="@id"/>
</view>
<view datapath="red" height="15" bgcolor="red">
<text datapath="@id"/>
</view>
<simplelayout axis="y"/>
</view>
<simplelayout axis="y" spacing="10"/>
</canvas>

antun
07-21-2003, 09:08 AM
This behaviour is actually a known issue with the LzReplicationManager. We're working on cleaning this up for the next release, but as yet the future behaviour is undefined, so I can't recommend a "correct" way to do it with the onaddsubview event.

For your situtation, this may be a workable solution:

Instead of using the onaddsubview event, use an oninit-time method on the view that will get added as a result of the replication.

Does that help you at all?

-Antun

sfarrow
07-21-2003, 09:22 AM
Could you explain what you mean by an "oninit-time" method?

antun
07-21-2003, 12:56 PM
Something like:


<method event="oninit">
// Script to be called at init-time
</method>


-Antun