PDA

View Full Version : Change dset source within a class


OLaszloFan
03-07-2007, 02:22 PM
Hi:
I am interested in being able to change an external xml source file reference in a local dataset which is used within a class.


I updated the example so that with each class calls an alternate xml source is referenced. Note: I used the same reference to simply the example.



I am not sure why I can't get the weather data to update and display following the push of the Fetch Weather button. Can anyone please try my code and help me problem solve.

Appreciate the help.


Patrick


<canvas debug="true">

<class name='weatherBug' extends="window" height="300" width="400" closeable='true' title="Get Weather">

<attribute name="dsetsource" value="http://www.laszlosystems.com/cgi-pub/weather.cgi?zip=" type="string" />

<dataset name="weatherdata" request="false" src="http://" ondata="classroot.txtURL.setText(classroot.weatherdata.src )" />

<simplelayout axis="y" />
<text>Enter a Zipcode:</text><simpleinputtext name='zip' width='100'>11023</simpleinputtext >

<button>Fetch Weather
<handler name="onclick" ><![CDATA[
var z = "${classroot.dsetsource}" + classroot.zip.getText();
local:classroot.weatherdata.setSrc(z);
local:classroot.weatherdata.doRequest();
]]></handler>
</button>

<grid datapath="local:classroot.weatherdata:/weather" contentdatapath="forecast/day" width="100%" />
<text name='txtURL' width="100%" ><i>(weatherdata.src)</i></text>

</class>

<weatherBug name="weatherBug1" x="200">
<attribute name="dsetsource" value="http://www.laszlosystems.com/cgi-pub/weather.cgi?zip=" type="string" />
</weatherBug>

<weatherBug name="weatherBug2" y="20">
<attribute name="dsetsource" value="http://www.laszlosystems.com/cgi-pub/weather.cgi?zip=" type="string" />
</weatherBug>

<button y="310" >Launch Another Instance
<handler name="onclick" ><![CDATA[
var temp = new weatherBug();
]]></handler>
</button>

</canvas>

d~l
03-08-2007, 04:52 AM
I have not got round to updating my last post (another thread) but I'll post a new version later today.

Meanwhile the script I suggested was in error ..

var z = "${classroot.dsetsource}" + classroot.zip.getText();

should be simply

var z = classroot.dsetsource + classroot.zip.getText();


....

and for launching weatherBug by script read this .



http://www.openlaszlo.org/lps/docs/guide/class-inheritance.html

6. Instantiating classes through script

In general, instantiation of objects happen using tags.
For instance, assuming <class name="myclass"> is declared,
you can create an instance of that class by writing <myclass/>.
However, there may be times when you will need to instantiate an object using script.
The script instantiation syntax for classes looks like:

var myobject = new myclass(parent, attributes, children, instcall)

where:

parent is where your object will be placed in the node hierarchy.
If it doesn't matter, then you can pass null.
If you are creating a subclass of view and the parent is null,
the canvas will be the parent of this object.

attributes is a hash of attribute values that get passed into the object.
For example, if you wanted to instantiate a new view with a different
bgcolor, width, and height, you could pass in {bgcolor: 0xff0000, width: 50, height: 50}.

children is the array of child views this object encapsulates.
The OpenLaszlo Runtime instantiator is responsible for passing in
the children of this object based on the LZX hierarchy. You will generally set this to null.

instcall is a boolean value that determines when this object will be instantiated.
If false, the instantiation of this object will be immediate, otherwise,
its instantiation will be synchronized with the rest of the view system.
See Appendix A, Understanding Instantiation.

All these parameters are optional. Not setting any of these arguments
(e.g., new myclass()) is equivalent to new myclass(null, null, null, 0).

OLaszloFan
03-08-2007, 02:12 PM
d~l:
The next step for my Wizard App is to be able to call a class like the weatherBug App class and read xml source from an external xml file which lists other xml source files to display in lists, textlistitems, grids and trees.

This example really helps me understand the dynamic class concepts which reference xml datafiles.

Thanks for your help and the Instantiating Classes Through Script information. The more information and examples I can get the better.

Patrick