PDA

View Full Version : updateData not updating XML src?


spoco2
08-07-2005, 06:50 PM
Hi fellow Laszlo developers,

Myself and a co-worker are building our first Laszlo application, and by and large are very impressed with it.

I, however have started running into some walls in regards to datapaths/pointers/nodes etc.

Here's what I'm trying to do:

* We have a canvas that objects are being dropped onto, once there they are dragged around and snapped to a grid etc, for visual layout purposes.
* Each of these objects is an instance of a class called 'VisualObject'
* Each of these VisualObject class instances has an associated attribute which is an instance of a DataObject.
* When a VisualObject is doubleclicked on, a popup window is present that allows the user to update/view/enter the data from the DataObject associated with the VisualObject. They then click on an 'Update' button and it should write the changes back to the db (or for this proof of concept, an XML file).

The Dataset is set in the class library as such:

<dataset name="dset" autorequest="true" type="http" src="../data/gh_data.xml"/>

And the Dataobjects just set their datapath to be a particular point in that dataset. When the popup window is called, it is passed the datapath from the DataObject and uses that to display its contents for editing.


Here are my issues that I hope you guys can help me with:
1. I can't get the DataObject to point at the exact record I want, only the container... I thought the syntax would be of the sort:
this.dp = "dset:/ghdata/campaign[@myName=this.myname]";

but that doesn't result in a valid datapointer

2. Assuming that 1 can be fixed... at present, with only one record in each category, the updateData only seems to work on a local copy. Any changes I make to the data are reflected on subsequent openings of the popupwindow during that session, but if I reload the application all data is back to square one. What am I doing wrong here?

Thanks in advance to anyone that has got this far and can help! :D

Let me know if any more info is required.

Regards,
Simon O'Connor

The XML format is:
<ghdata>
<campaign ID="1" myName="Campaign_1" CreateDate="01/01/2001" Creator="Me" Description="Here is the campaign description, go wild with it... go wild"
Budget="1234" ExpectedListsize="1000" ExpectedWashrate="0.15" ExpectedContactRate="0.3"
/>
<campaigngroup ID="2" myName="CampGroup_1" CreateDate="01/01/2001" Creator="You" Description="Here is the campaign description, go wild with it... go wild"
Budget="1234" StrategyName="Winback" ExpectedListsize="10000"
/>
</ghdata>

antun
08-08-2005, 09:18 AM
The snippet of code below will create a variable called "dp" with the XPath as a string on the object that "this" refers to. There are a number of ways to get a datapointer that points to the right place in data. You could do:


var dp = new LzDatapointer();
dp.setXPath( "dset:/ghdata/campaign[@myName=this.myname]" );
// then do whatever you want with the datapointer


1. I can't get the DataObject to point at the exact record I want, only the container... I thought the syntax would be of the sort:
this.dp = "dset:/ghdata/campaign[@myName=this.myname]";

but that doesn't result in a valid datapointer


You can't modify an XML file on a server directly from a Laszlo application. Instead you should have a service (PHP, JSP, Perl etc.) that the dataset points to and modifies your XML file (or communicates with a database).

-Antun

2. Assuming that 1 can be fixed... at present, with only one record in each category, the updateData only seems to work on a local copy. Any changes I make to the data are reflected on subsequent openings of the popupwindow during that session, but if I reload the application all data is back to square one. What am I doing wrong here?

spoco2
08-08-2005, 03:18 PM
Antun,

Thankyou indeed for your reply. We nutted out the pointer issue yesterday with:

this.dp = "dset:/ghdata/campaigngroup[@myName ='"+ this.myname+"']";
this.setDatapath(this.dp);

And passed the this.dp around rather than the actual datapointer...(having the object it's passed to setting its datapath using it) although I am having some odd behaviour when I change the 'myname' attribute when editing, so I might switch to your method.

Thanks for the info on the lack of updating of the XML file... can indeed fix that.

Thanks! :D

tim_melton
08-19-2005, 09:00 AM
Writing to a local file in the application folder would seem to be a critical issue if you wanted to make a stand alone application, which uses flat files for its data.

Which is what we orginally had envisioned since Laszlo can make a stand alone swf.


===============================================
You can't modify an XML file on a server directly from a Laszlo application. Instead you should have a service (PHP, JSP, Perl etc.) that the dataset points to and modifies your XML file (or communicates with a database).
================================================== =

antun
08-19-2005, 09:36 AM
The Flash player cannot write to the local filesystem - that's a security restriction.

Take care,

Antun

spoco2
08-21-2005, 04:18 PM
A final question on this... I'm starting to get the hang of this, but don't quite get the whole Datapath vs dataset vs datapointer distinction.

The way I thought it worked was:

A Dataset - The set of data that we're talking about, an XML file, or a pointer to an XML defined set in the code, or a newly created dynamic XML set.
A Datapath - A handle by which you can start working with a dataset, effectively a directory/file pointer (much like doing a directory command in DOS or Unix).
A Datapointer -A pointer further refining the datapath, and can be relative.

At least that's what I thought... my problem seems to be that I keep loosing the base dataset/root path off my datapath when I set a datapointer on it to some 'sub-directory'... The way I'm trying to work is to not have to know about the dataset/root path within objects, they only should have to know about their pointer... but when I do a search through the dataset for an item by it's @name attribute, and find it using an:
if(this.xpathQuery("@name")==whatIAmSearchingFor)


I set a temporaty XPath by way of using:

this.tempXPath=this.xpathQuery()

which certainly seems to select the correct node.

But when I try and use this result to set the point to do a new Addnode or whatever I'm doing at that point I get the dreaded couldn't find dataset for error.

It's really driving me nuts! So close, yet so far at this juncture.

I still want to write out a nice little guide on how to use these things once I've nutted it out with your help, as I think it'd be very valuable in these forums.

Simon