| Page 1 of 1 | [ 7 posts ] |
|
I'm trying to display data that was retrieved from a server.
The server receives xml via an HTTP post, and responds with XML. According to Firebug, the following returns xml in the HTTP response as expected: Code: postData = "<uRequest/>"; myDS = new YAHOO.util.XHRDataSource("http://address/u"); myDS.connMethodPost = true; myDS.responseType = YAHOO.util.DataSource.TYPE_XML; myDS.responseSchema = { resultNode: "U", fields: ["dId", "dN"] }; myColumnDefs = [ {key:"departmentId"}, {key:"departmentName"} ]; connNumber = this.myDS.makeConnection(postData); But, how do I place the XML in my DataTable. I've tried variants on the following: myDataTable = new YAHOO.widget.ScrollingDataTable("loc-table", myColumnDefs, myDS.makeConnection); But, the table indicates a data error. Seems like I need to do something like: myDS.objectRequest = postData Hence, the post. Thanks very much. |
|
A snippet of the XML response (exactly as it shows in firebug) would be helpful. Do you see an XHR request in firebug?
|
|
DataTable will call the corresponding methods in DataSource to retrieve the information once instantiated. You don't need to call makeConnection nor any other method in DataSource yourself. There are plenty of examples on how to read XML, go back to basics, I guess you are doing trial and error, but you're far gone on a dead end.
Also, the column keys don't match the fields in the responseSchema and, perhaps, there is some mismatch in between your XML and the responseSchema you are giving. XML is very touchy, the <?xml ...> processing instruction has to be there in the very first position, no whitespace allowed, otherwise the XML parser might ignore it (and that is part of the browser, not of YUI so there is nothing to be done there). Your post data would give such an error if the response comes like that, with not processing instruction at the start. |
|
Thanks very much for the posts. Below I've tried to be more complete.
The following code is run as a result of a button click: Code: myDS = new YAHOO.util.XHRDataSource(url/servlet); myDS.connMethodPost = true; myDS.responseType = YAHOO.util.DataSource.TYPE_XML; myDS.responseSchema = { resultNode: "User", fields: ["departmentId", "departmentName"] }; myColumnDefs = [ {key:"departmentId"}, {key:"departmentName"} ]; myDS.sendRequest("<UsersRequest/>") myDataTable = new YAHOO.widget.ScrollingDataTable("gx-table", myColumnDefs, myDS); After sendRequest, Firebug shows: HTTP Post source text: <UsersRequest/> HTTP Response: <?xml version="1.0" encoding="UTF-8"?> <Users> <User departmentId="2" departmentName="ALL Departments" groupId="2" groupName="DEVELOPMENT" supervisorDisplayName="root" supervisorId="19" userDisplayName="Mike" userEmail="mike@co.com" userFirstName="Mike" userId="17" userLastName="GoodWorker" userLogin="mg"/> + more <User> elements </Users> After myDataTable = new, Firebug shows: HTTP Post source text: *empty* HTTP Response: <?xml version="1.0" encoding="UTF-8"?> <Response code="CMVecEx04" message="Exception:Failed to parse schema document" type="Error"/> The response is our server saying you didn't post the correct data. In the html at the end myDataTable display the table with departmentId and departmentName as headers. The body shows: No records found This is as expected, since no records were returned in the HTTP exchange. Summary Our servlet requires an HTTP Post that contains: <UsersRequest/>. Calling sendRequest works just fine. But, when myDataTable = new is called, the Post text is not present and the call doesn't return any data. So how can I obtain data in the ScrollingDataTable? Thanks very much for your help. |
|
As I said before, you don't need to call any method of DataSource, in fact, you must not. Neither makeConnection nor sendRequest. Creating the DataTable instance will automatically call whatever needs to be called in DataSource.
To post an initial request to the server, you use the initialRequest configuration attribute, like this: myDataTable = new YAHOO.widget.ScrollingDataTable("gx-table", myColumnDefs, myDS, {initialRequest:"<UsersRequest/>"}); I would also suggest you add a parser to departmentId: {key:"departmentId", parser:"number"}, otherwise, those numbers will be read as strings and if you sort them, they will sort like: 1,11,12,13,2,21,22 and so on. |
|
Satyam, Per your suggestion, I changed the code to the following:
Code: // myDS.sendRequest("<UsersRequest/>") myDataTable = new YAHOO.widget.ScrollingDataTable("gx-table", myColumnDefs, myDS,, {initialRequest:"<UsersRequest/>"}); It works as expected. Thanks! Follow-on Questions What are the best practices for: 1. Refreshing the table with the same POST text? 2. Refreshing the table with the same POST text on a regular interval? 3. Refreshing the table with different POST text? Thanks very much. |
|
See:
http://www.satyam.com.ar/yui/#requery The requery method (or something very much like it) is what you need. If you don't have server-side paging or sorting, the 2.6 version is smaller and still works. If you do have or plan to have server-side sorting and pagination please do read the warnings in the 2.8 version because it works in very limited circumstances, that is why this method is not part of the DataTable, it has too many caveats. To repeat the same request, use this method in a function fired by window.setInterval or YAHOO.lang.later |
| Page 1 of 1 | [ 7 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group