PDA

View Full Version : Bug in textlistitem multiselected


ctenov
12-07-2006, 04:21 AM
Hello guys,

I have noted a strange behavior when multiselecting textlistitems. Maybe any guru could help. See the code:

<canvas bgcolor="#EAEAEA" width="640" height="700">

<dataset name="items">
<item value="item1" selected="true">item one</item>
<item value="item2">item two</item>
<item value="item3">item three</item>
<item value="item4" selected="true">item four</item>
<item value="item5">item five</item>
<item value="item6">item six</item>
</dataset>

<list id="a3" x="10" y="20" multiselect="true" width="130" shownitems="7">
<textlistitem datapath="items:/item" text="$path{'text()'}" value="$path{'@value'}" selected="$path{'@selected'}"/>
</list>

<?ignore
<dataset name="ditem" src="http://someurl/ditem.xml" request="true"/>
<textlistitem datapath="ditem:/items/item" text="$path{'text()'}" value="$path{'@value'}" selected="$path{'@selected'}"/>
?>

</canvas>

If you execute the above code all things happens well: two items are selected.

But if you get the dataset and put it in a file (ditem.xml) and reference it by 'http://...' like I exemplify in "ignore" part of the code, no more than one item (the last one) is selected.

I search a lot and discover that if you go into "baselist.lzx" file and change line 358 from

"} else if (this._initcomplete) {"

to

"} else if (false) {"

two itens are selected as expected but in this case I canīt do any other selection because I mess with the logic of the baselist's program.

This behavior says me that something about '_initcomplete' is diferent between the aproachs (embedded dataset x http dataset), but I canīt discover how to fix it with no mess of behavior.

Could anyone help ? Thanks !

senshi
12-08-2006, 11:37 AM
With an embedded dataset the data will be present at instantiation time, so replication can start immediately.
But with a http-dataset, replication takes action after loading the data, which is after instantiation time.

Two different approaches:

1. Init the list after receiving the data

<list id="a3" ... initstage="defer" />
...

<!-- ditem is your dataset-->
<handler name="ondata" reference="ditem" >
a3.completeInstantiation();
</handler>


2. After last clone's init, select the items

<textlistitem text="$path{'text()'}" value="$path{'@value'}" >
<datapath xpath="item" >
<method event="onclones" args="clones">
var lastclone = clones[clones.length-1];
if( !this["doneDel"] ){
this.doneDel = new LzDelegate( this, "replicationDone" );
} else {
this.doneDel.unregisterAll();
}
this.doneDel.register( lastclone, "oninit" );
</method>
<method name="replicationDone">
<![CDATA[
var cl = this.clones;
var arr = [];
var arrlen = 0;
for( var i=0; i<cl.length; ++i )
if( cl[i].datapath.p.getAttr( "selected" ) == "true" )
arr[arrlen++] = cl[i];
a3.select( arr );
]]>
</method>
</datapath>
</textlistitem>


PS:
Changing "} else if (this._initcomplete) {" was a false friend, the items looked like they're selected, but a a3.getSelection() would have shown they aren't.

ctenov
12-11-2006, 03:08 AM
Hello Senshi,

thanks so much !

After many days trying a lot of approachs with no sucess your advice was a cup of cold water in desert.

Sorry for the delay but I didnīt receive in my email the comunication of your response and only today I see it.

Please more one thing: your second approach does the job OK, but I canīt do the same with the first approach. Only to satisfy my curiosity what is my error ...

My code:


<list id="a3" x="10" y="20" multiselect="true" width="130" shownitems="7" initstage="defer">
<textlistitem datapath="ditem:/items/item" text="$path{'text()'}" value="$path{'@value'}" selected="$path{'@selected'}">
<handler name="ondata" reference="ditem" >
a3.completeInstantiation();
</handler>
</textlistitem>
</list>


I have tried this too although I recognizes that former is the most right form


<list id="a3" x="10" y="20" multiselect="true" width="130" shownitems="7" initstage="defer">
<handler name="ondata" reference="ditem" >
a3.completeInstantiation();
</handler>
<textlistitem datapath="ditem:/items/item" text="$path{'text()'}" value="$path{'@value'}" selected="$path{'@selected'}">
</textlistitem>
</list>


Thanks a lot

senshi
12-11-2006, 08:50 AM
You shouldn't place the handler in the <list>- resp. the <textlistitem>-tag.
Somehow the handler won't be created...if it is placed outside it will work.

Just made some test cases about this issue. This is definitely a bug and I will report it in JIRA.

ctenov
12-11-2006, 09:08 AM
OK,

putting the handler outside list it functions very nice.

Thanks so much