PDA

View Full Version : dynamic widget/dataset binding


twashing
08-19-2003, 10:07 AM
I have a class that needs to talk to a server resource. The component needs a dataset i) so that it can pass info btn client and server using 'doRequest'. ii) so that child components can bind thier datapaths to the dataset. It will not know where that resource is until something creates it and gives it server information.

I first tried to pass my class a datapointer. I am able to get a dataset from the datapointer with 'pointer.getDataset()'. I can use that dataset to make a GET request. Passing server information is easy. I am having difficulty binding components to a dataset that was passed by a method.

ex)

<class name="clazz">
<attribute name="postset"/>
<attribute name="getset"/>

<method name="setPOST" args="pp">
this.postset = pp.getDataset();
</method>
<method name="setGET" args="gp">
this.getset = gp.getDataset();
</method>

<!-- THIS IS THE BIT THAT DOES NOT WORK -->
<wdiget datapath="getset:/" name="zzz"/>
</class>



** But I CANNOT find a way to bind child components to a dataset that was passed into a class. All examples show widgets (texts, dropdowns, etc) binding to a dataset that been hardcoded under the canvas. I've tried setting the "when" attribute to "always" - not luck.

Has anyone tried this before? Has anyone found a solution?


Timothy Washington

antun
08-19-2003, 10:39 AM
I hope I've understood what you're asking here:


<canvas debug="true">
<dataset name="myDataset">
<myroot myattr="foo" />
</dataset>

<class name="clazz">
<attribute name="postset"/>
<attribute name="getset"/>
<attribute name="passedds" />

<!-- Here's where the dataset is getting passed -->
<method event="oninit">
myinst.setGET( this.passedds );
</method>

<method name="setPOST" args="pp">
this.postset = pp.getDataset();
</method>

<method name="setGET" args="gp">
this.getset = gp.getdataset();

// Build up the XPath string
var dsname = this.getset.name;
var dp = dsname + ":/myroot[1]";
debug.write( "Here is the datapath we will set: " + dp );

this.zzz.setDatapath( dp );
</method>

<!-- Start with a blank dataset. I belive there's a bug in v1 that
prevents you from setting datapaths using setDatapath(), if
you didn't include the datapath attribute in the view. That's
why we're giving it an empty value here. -->
<view width="100" height="50" bgcolor="red"
datapath="" name="zzz">
<method event="oninit">
// We can't call the setDatapath() method here because
// subviews get instantiated first, so the setGet() method
// in this parent will not have been called.
</method>
<!-- If the datapath gets set correctly, then this text field
will show: -->
<text datapath="@myattr" />
</view>
</class>


<clazz name="myinst" passedds="$once{canvas.datasets.myDataset}" />

</canvas>


You'd basically build up the XPath you want to set as a string (in fact that's how you frequently work with XPaths in Laszlo). Then call the setDatapath method to set it to that string.

Let me know if this is what you were asking about, or if I've completely missed the point.

-Antun

twashing
08-20-2003, 11:51 AM
That works. Thanks for the response.