View Full Version : "Call By Name"-Problem of <text>-Component being in <gridcolumn>
MBachstein
04-24-2008, 06:38 AM
Hello,
I want to call a <text>-Component by name, which is in a <gridcolumn>-Component. The compiler gives here an error:
Debug.evalCarefully("ChangingAttributesInText.lzx", 7, function () {return myText;}, this) has no properties
If the <text>-Component is in a <view>-Component there is no compiler error and it works fine.
Now, is there a possibility to call this component by name?
Here are the source codes:
This works:
<canvas debug="true" >
<class name="myClass" extends="view">
<text name="myText" multiline="false" width="0"/>
<handler name="oninit">
myText.setText("Hello!");
</handler>
</class>
<view name="View">
<handler name="oninit">
var A = new myClass(this,{});
</handler>
</view>
</canvas>
Here the compiler gives an error:
<canvas debug="true" >
<class name="myClass" extends="gridcolumn">
<text name="myText" multiline="false" width="0"/>
<handler name="oninit">
myText.setText("Hello!");
</handler>
</class>
<view name="View">
<grid>
<handler name="oninit">
var A = new myClass(this,{});
</handler>
</grid>
</view>
</canvas>
Kind Regards,
Marc
rcyeager
04-24-2008, 07:12 AM
Don't be afraid to look inside the LZX component code. Also, try using the debugger to investigate how the grid looks at runtime.
If you peek inside basegridcolumn.lzx, you will see that it has a defaultplacement attribute set to "content".
So, you should find a content view within the gridcolumn at runtime that contains your views.
Try this.content.myText.setText() instead.
Robert Yeager
http://www.qrowd.com
http://www.cooqy.com
MBachstein
04-29-2008, 12:14 AM
Hello,
I still did not find out, how I can change parameters of a <text>-Component being in a <gridcolumn>-Component. :confused:
Does anyone of you have a clue?
Kind Regards,
Marc
rcyeager
04-29-2008, 06:33 AM
So, what happened in your oninit handler when you changed myText.setText() to this.content.myText.setText() like I suggested? Did that work?
Robert Yeager
http://www.qrowd.com
http://www.cooqy.com
MBachstein
04-29-2008, 06:44 AM
No, it did not work. There is the same error message that "this.content" has no properties.
I also tried to change the placement of the text-Component but this also did not work.
rcyeager
04-29-2008, 07:08 AM
The sample code on this thread is wrong, per the solution I provided on this other thread for you a few days ago:
http://forum.openlaszlo.org/showthread.php?t=11821
This sample code here is trying to modify a column that isn't constructed yet.
Robert Yeager
http://www.qrowd.com
http://www.cooqy.com
MBachstein
04-29-2008, 07:23 AM
That is exactly what I want. :)
This is a new issue. I want to construct the column dynamically and set the datapath of the text-Component on the fly.
rcyeager
04-29-2008, 07:48 AM
So can you take the solution code from http://forum.openlaszlo.org/showthread.php?t=11821 and modify it to show want you want to do?
Robert Yeager
http://www.qrowd.com
http://www.cooqy.com
MBachstein
04-30-2008, 04:24 AM
Hi,
this is what I want to do:
The gridcolumns shall be generated dynamically by instantiating the "universalGridColumn"-Class.
This class substitutes the two classes
<class name="myGridColumnA" extends="gridcolumn">
<text name="myText" datapath="Item/ItemContentA/text()" />
</class>
<class name="myGridColumnB" extends="gridcolumn">
<text name="myText" datapath="Item/ItemContentB/text()" />
</class>
of the example from http://forum.openlaszlo.org/showthread.php?t=11821 .
The problem is that I cannot call the <text>-Component in the <gridcolumn>-Component.
<canvas debug="true" >
<dataset name="DataDS">
<Itemlist>
<Item>
<ItemContentA>1A</ItemContentA>
<ItemContentB>1B</ItemContentB>
</Item>
<Item>
<ItemContentA>2A</ItemContentA>
<ItemContentB>2B</ItemContentB>
</Item>
</Itemlist>
</dataset>
<!-- The Output should be:
A | B
======|======
1A | 1B
2A | 2B
-->
<class name="myUniversalGridColumn" extends="gridcolumn">
<text name="myText"/>
<method name="initTextcomponentDatapath" args="myTextcomponentDatapath"><![CDATA[
// Here I want to set the datapath of the <text>-Component,
// so that the columngrid becomes filled with content
/* THIS LINE THROWS AN ERROR */
this.myText.setDatapath(myTextcomponentDatapath);
]]>
</method>
</class>
<class name="myGrid" extends="grid" datapath="DataDS:/Itemlist" contentdatapath="Item" width="600"
showvlines="true" showhlines="true">
<method name="init">
var columnobj = new myUniversalGridColumn(this,{text:"A"});
columnobj.initTextcomponentDatapath("ItemContentA/text()");
var columnobj = new myUniversalGridColumn(this,{text:"B"});
columnobj.initTextcomponentDatapath("ItemContentB/text()");
initTextcomponentDatapath
super.init();
</method>
</class>
<view name="View">
<myGrid/>
</view>
</canvas>
Kind Regards,
Marc
rcyeager
04-30-2008, 07:35 AM
I already explained that the grid columns don't get created until *after* the init() is complete. You can't call a method on something that doesn't exist.
Robert Yeager
http://www.qrowd.com
http://www.cooqy.com
senshi
04-30-2008, 09:11 AM
This is what I'd do:
Add a new attribute to the custom gridcolumn class, i.e. "textdatapath", and constrain that attribute to the text's datapath.
<class name="myUniversalGridColumn" extends="gridcolumn">
<attribute name="textdatapath" value="" type="string" />
<text datapath="$once{this.parent.textdatapath}" />
</class>
<class name="myGrid" extends="grid" showvlines="true" showhlines="true">
<method name="init">
new lz.myUniversalGridColumn(this, {text:"A", textdatapath:"ItemContentA/text()"});
new lz.myUniversalGridColumn(this, {text:"B", textdatapath:"ItemContentB/text()"});
super.init();
</method>
</class>
<myGrid id="foo" width="600" datapath="DataDS:/Itemlist" contentdatapath="Item" />
MBachstein
05-07-2008, 04:39 AM
Thank you so much, senshi!!
It works fine!
Kind Regards,
Marc
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.