PDA

View Full Version : Reusing a dataset in multi-file access


andys
03-22-2003, 01:41 PM
I am trying to read in a set of XML files. The names of these files (and even the number of them) are determined at run time, so I can't statically code datasets for each one.

I have create one generic dataset and associated a datapointer with this dataset. The dataset is created with autorequest=false.

Within a method (elsewhere in my code, not part of the datapointer) I grab my generic dataset (let's name it "ds") and execute:

- ds.setURL(...)
- ds.doRequest()

This, in itself, works fine. The datapointer's ondata event gets called after the doRequest and is able to read in the set URL's data.

I then enhanced the above-mentoned method to do the following:

- ds.setURL(...)
- ds.doRequest()
- ds.setURL(...)
- ds.doRequest()

The idea being to read in one file and then reuse the dataset to read in a different file. This, however, didn't work. It appears that the doRequest() call is asynchronous and my second setURL gets execute before the first request completes. I end up reading in the same file twice.

How can I dynamically read in multiple files? Is there a way to serialze the doRequest call?

If this wasn't clear I can supply some example code.

Thanks!

Andy.

antun
03-22-2003, 02:12 PM
Have you tried setting the autorequest attribute to false BEFORE you set the URL. I'm not sure but it may be true by default, and the request happens when you set the url:

- ds.setAutorequest ( false )
- ds.setURL(...)
- ds.doRequest()

Does that help?

-Antun

andys
03-22-2003, 02:21 PM
I had already set autorequest to false in the definition of the dataset:

<dataset name="generic_dataset" src="none" type="http" autorequest="false"/>

In your response, Antun, you pasted the first example of my code, the example where I have one doRequest:

- ds.setURL(...)
- ds.doRequest()

I want to be sure that I was clear, _that_ example works perfectly. It's the second example:

- ds.setURL(...)
- ds.doRequest()
- ds.setURL(...)
- ds.doRequest()

that is failing. It is this second example where the first doRequest() call returns before the associated datapointer's ondata method gets called. Therefore the dataset's setURL gets modified before the HTTP request has returned.

It appears (though I may be misunderstanding things) that the problem is that I am not forcing the doRequest() to wait until an HTTP Response has arrived. I suspect I need to wait for the response before I go reusing the dataset.

Was that as clear as mud?

Andy

antun
03-22-2003, 03:34 PM
I'm going to have to do some research to get you a complete answer. I'm not sure if it's a good idea to reuse datasets like you're doing. For a start, what is the script supposed to do when you make a request? Should it hang, until the request is completed, and the data returned? That would make things very slow, but you would be able to reuse datasets.

Before I get back to you, one thing you might want to try is create datasets using script, so you don't have to declare them.

Something like:-


ds = new LzHTTPDataset( canvas, { name: 'myDataset', autorequest: false } );
ds.setURL( ... );
ds.doRequest();


-Antun

andys
03-22-2003, 05:00 PM
Antun,

I think creating a dataset is the right way to go. I wasn't sure how to do it via script in part because I didn't understand the relationship/requirement for a datasource.

I have gone ahead and used your code. However the dataset's getAllResponseHeaders always returns false.

Perhaps the dataset isn't actually going out and fetching the named file.

Is there anything else I need to do to cause the dataset to actually retrieve the data?

Also, note that I additionally need to create a datapointer via script. I assume something along the lines of the following is correct:

dp = new LzDatapointer( this, { ondata: this.processData, onerror: this.showError, xpath: 'myDataset:/' } );

andys
03-23-2003, 09:10 PM
Antun,

I was successful at dynamically creating a dataset by also creating a datasource.

The code that seems to work follows. Note that the use of "this" below is because the code is part of a method of a user-defined class. Therefore "this" refers to the current instance of my class and it's associated user-defined attributes.


this.dsource = new Datasource(this);
this.ds = new LzHTTPDataset( this, { name: this.sourceURL,
type: "http",
autorequest: false } );
this.ds.initialize(this.dsource);
var xp = this.sourceURL + ":/"
this.dp = new LzDatapointer( this, { ondata: this.processData,
onerror: this.showError,
xpath: xp } );
this.ds.setURL(this.sourceURL);
this.ds.doRequest();

bpinheiromg
05-08-2006, 12:23 PM
I’m having almost the same problem. but i cant make andys example above work on my project... im actually didn’t understand it…

There is a simple difference. Im using 2 different dataponters pointing to different datasets like the code bellow.

// on the main program
<dataset name="ds1" type="http" ondata="view1.newData();/>
<dataset name="ds2" type="http" ondata="view2.newData()/>

// on a select event from one grid
ds1.setSrc("...");
ds1.doRequest();
ds2.setSrc("...");
ds2.doRequest();

// inside each view i have
<datapointer id="dp1:/data/item"/>
//and
<datapointer id="dp2:/otherData/otherItem"/>


My program should actualize 2 views with the data from 2 different datasets when the user selects a desired line in a grid.
This works fine when i have only one doRequest() call. But when i have 2, only one is actualized.

when im debugin, i check the xPath of the datapointers using "dp1.getXPath()" and one is ok and the other is null.

Like this i can only actualize one view each time, and i can never know witch one will be.

Any one have any idea how to fix it?
I have search all the topics in this forum and nothing like this...

thanks all in advance!

bfagan
05-08-2006, 06:43 PM
andys,

Have you tried setting queuerequests="true" on the dataset?

bpinheiromg
05-09-2006, 05:28 AM
I tried with queuerequests="true" but it isn't working yet...

I was making some tests and have noticed that some times the two requests returns and both views recive his actualizations. but only some times... Most of the time, only one receive his data... generaly the second.

I dont know what more i can do.

l0gin
06-07-2006, 02:59 PM
... in ondata event to reprocess another url stored in an array.