PDA

View Full Version : Problem dynamically filling in dataset assoicated with a view


andys
03-23-2003, 09:22 PM
I have created a view and subviews that display a table of rows. I'm using a datapath to build the rows and their data. This is basically just following the example in the "data" tutorial.

However, in this case I am dynamically building up the dataset. The dataset is initially empty. I have an onclick method for the view that builds up the dataset.

The problem I'm having is that no data is being displayed upon clicking the mouse. In the debugger window I can see a number of error messages about my referenced XML elements not being found. I'm fairly certain I am creating them with the correct names and structure; the view will fill in properly if I reference a pre-built (in-line) dataset.

My current guess is that the view is getting notified of a dataset update while my onclick method is in the middle of updating the dataset. I tried making use of the dataset 'lockFromUpdate' method, but without success. I am unsure of what kind of item to pass for the "who" parameter of that method.

Any advice on how to get this table view working?

Thanks.

Andy

antun
03-23-2003, 09:35 PM
Can you post some code?

-Antun

andys
03-24-2003, 09:45 AM
Antun,

NOTE: Post updated with new attachment. Earlier attachment had view's datapath set to the input dataset, which wasn't the failure mode. Current attachment has view using the output dataset (channelWindow_ds) which creates the error scenario.

Attached you should find my example code. This is a test app for me to understand how (if) I can dynamically create a dataset and have a view that is mapped to that dataset automatically update itself.

Just as a brief guide of what this code is doing:

- Two datasets are defined:
. "data" holding some test input data
. "channelWindow_ds" holding the data to be displayed in the view table

- Person is a class that processes the input data. In the future it will transform the input dataset, right now I'm just using it to copy the input ds without changing anything.

- The main view is channelWindow. It has a datapointer that reads in the source ds and builds up the Person class.

(As an aside, note how I had to leave off the xpath for the data_dp datapointer and assign it in the oninit event for the channelWindow. If I assigned the xpath in the datapointer it seemed to execute the code before the Person class existed. So this technique delayed it. Definitely wasn't obvious that I'd have to do this!)

- fillView is a method that, upon a mouse click, takes the data generated by the Person class and fills in the output channelWindow dataset.

- myTable is the set of views that is supposed to display the output dataset.

What is interesting is that if I change the channel_row datapath to point to the input dataset the table displays correctly. When it's mapped to the output dataset it fails. I'm pretty sure the output dataset is formatted correctly.

Thanks for your help.

Please tell me if I'm doing something in an unexpected or unrecommended manner.

Andy

metasarah
03-25-2003, 04:32 PM
Andy,

You have the right idea, but there is a small bug in your code for creating the dataset. A good way to debug this kind of thing is to print out an xml representation of the data:
debug.write(channelWindow_dp.serialize());

In fillView, you call "selectChild" which selects the first child node. For later iterations, you need to also call selectNext, to select the correct child node:

channelWindow_dp.selectChild();
if (i) {
channelWindow_dp.selectNext(i);
}

When I made this small change, the table displayed fine.

Sarah

adam
03-25-2003, 04:41 PM
Hi Andy,
I thought you might also be interested in the "new:/" feature of datapaths.

Giving your view this datapath creates a new local dataset and binds the datapath to that set. You can also specify a starting node for your empty dataset by using a name after the :/ -- e.g. <view datapath="new:/person"

Later, if you need to get a pointer to that datset, you can do so by duplicating the datapath -- e.g.

var mypointer = this.datapath.dupePointer( );


paging.lzx in the examples directory has a good example of this.

andys
03-25-2003, 09:41 PM
Sarah and Adam,

Thank you. I apologize for posting an item where the bug was in my code.

I did use serialize() during my debug -- but that didn't stop me from looking past the mistake. I didn't see the end of the dataset where, I now realize, I would have found </person></person></person>. (None the less, the mistake was visible in the first part.)

As I write this I just discovered that I could have set the cavas width much larger and then I would have seen the whole string in the debugger window. That's interesting.

Regarding a datapath of 'new:/', yes that is probably just what I want for my main application. That will be better than defining constant-named datasets.

Thanks for your help.

Andy