fortneci
asked on
YUI DataTable with Data Source as a Java Servlet generating XML
I am working to implement the YUI DataTable (http://developer.yahoo.com/yui/datatable/) with my data source as a Java servlet that creates XML output.
What I know:
outputter.outputString(jDO MDoc); will output the XML structured as:
<ResultSet><Result><ROUNDS >3</ROUNDS > ..... </Result></ResultSet>
I get the Javascript error 'no element found' http://url/LeagueStandings?get=all&ouput=xml
The table appears with the column headers, but the data does not appear.
No Exceptions are being thrown.
The Servlet Code:
RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
//create the XML from recordset
Document jDOMDoc = rsxml.build();
results.close();
XMLOutputter outputter = new XMLOutputter() ;
StringWriter writer = new StringWriter() ;
outputter.output( jDOMDoc, writer );
writer.close() ;
//respond with output stream
rep.setContentType("text/x ml");
rep.getOutputStream();
Javscript:
var myColumnHeaders = [
{key:"ROUNDS",text:"ROUNDS "},
{key:"USERNAME",text:"USER "},
{key:"BIRDIES",text:"BIRDI ES"},
{key:"PARS",text:"PARS"},
{key:"BOGIES",text:"BOGIES "},
{key:"DOUBLES",text:"DOUBL ES"},
{key:"GH",text:"GH"},
{key:"FH",text:"FH"},
{key:"PUTTS",text:"PUTTS"} ,
{key:"SCORES",text:"SCORES "},
];
var myColumnSet = new YAHOO.widget.ColumnSet(myC olumnHeade rs);
// Show over 1000 records
var myDataSource = new YAHOO.util.DataSource("http://url/LeagueStandings");
// Set the responseType as XML
myDataSource.responseType = YAHOO.util.DataSource.TYPE _XML;
// Define the data schema
myDataSource.responseSchem a = {
resultNode: "ResultSet.Result", // Node name of each result item
fields: ["ROUNDS","USER","BIRDIES" ,"PARS","B OGIES","DO UBLES","GH ","FH","PU TTS","SCOR ES"] // Field names
};
//Pagination
var initialRequest = "get=all&output=xml";
var oConfigs = {
caption:"Example: Paginated Over XHR",
initialRequest:initialRequ est,
pageCurrent: 1,
rowsPerPage: 100,
startRecordIndex: 1,
pageLinksLength: 10,
rowsPerPageDropdown: [25,50,100,500]
};
var myDataTable = new YAHOO.widget.DataTable("pa ginated", myColumnSet, myDataSource, oConfigs);
What I know:
outputter.outputString(jDO
<ResultSet><Result><ROUNDS
I get the Javascript error 'no element found' http://url/LeagueStandings?get=all&ouput=xml
The table appears with the column headers, but the data does not appear.
No Exceptions are being thrown.
The Servlet Code:
RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
//create the XML from recordset
Document jDOMDoc = rsxml.build();
results.close();
XMLOutputter outputter = new XMLOutputter() ;
StringWriter writer = new StringWriter() ;
outputter.output( jDOMDoc, writer );
writer.close() ;
//respond with output stream
rep.setContentType("text/x
rep.getOutputStream();
Javscript:
var myColumnHeaders = [
{key:"ROUNDS",text:"ROUNDS
{key:"USERNAME",text:"USER
{key:"BIRDIES",text:"BIRDI
{key:"PARS",text:"PARS"},
{key:"BOGIES",text:"BOGIES
{key:"DOUBLES",text:"DOUBL
{key:"GH",text:"GH"},
{key:"FH",text:"FH"},
{key:"PUTTS",text:"PUTTS"}
{key:"SCORES",text:"SCORES
];
var myColumnSet = new YAHOO.widget.ColumnSet(myC
// Show over 1000 records
var myDataSource = new YAHOO.util.DataSource("http://url/LeagueStandings");
// Set the responseType as XML
myDataSource.responseType = YAHOO.util.DataSource.TYPE
// Define the data schema
myDataSource.responseSchem
resultNode: "ResultSet.Result", // Node name of each result item
fields: ["ROUNDS","USER","BIRDIES"
};
//Pagination
var initialRequest = "get=all&output=xml";
var oConfigs = {
caption:"Example: Paginated Over XHR",
initialRequest:initialRequ
pageCurrent: 1,
rowsPerPage: 100,
startRecordIndex: 1,
pageLinksLength: 10,
rowsPerPageDropdown: [25,50,100,500]
};
var myDataTable = new YAHOO.widget.DataTable("pa
I'm not sure this goes the whole nine yards, but it appears that you have an error in the fields array. You're showing "USER", when the name of the key is "USERNAME"
ASKER
I changed it all to USERNAME to clear up any discrepancy, but the result is the same. I still get the 'no element found' http://url/LeagueStandings?get=alll&output=xml JAVASCRIPT ERROR. My thought is that I am getting the error because my XML data source isn't being read. I validated in the Servlet that the jDOMDoc is creating XML, but I haven't been able to validate that it is being returned in the response of the servlet, any suggestions on how to do that?
Can you post the XML?
ASKER
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet>
<Result>
<ROUNDS>3</ROUNDS>
<USERNAME>testuser</USERNA ME>
<BIRDIES>2</BIRDIES>
<PARS>13</PARS>
<BOGIES>28</BOGIES>
<DOUBLES>11</DOUBLES>
<GH>10</GH>
<FH>10</FH>
<PUTTS>108</PUTTS>
<SCORES>264</SCORES>
</Result>
</ResultSet>
<ResultSet>
<Result>
<ROUNDS>3</ROUNDS>
<USERNAME>testuser</USERNA
<BIRDIES>2</BIRDIES>
<PARS>13</PARS>
<BOGIES>28</BOGIES>
<DOUBLES>11</DOUBLES>
<GH>10</GH>
<FH>10</FH>
<PUTTS>108</PUTTS>
<SCORES>264</SCORES>
</Result>
</ResultSet>
ASKER
If i just try to hit the servlet, I am getting the following error.
XML Parsing Error: no element found
Location: http://url/LeagueStandings
Line Number 1, Column 1:
XML Parsing Error: no element found
Location: http://url/LeagueStandings
Line Number 1, Column 1:
ASKER
Found the problem and got this resolved. I am posting the updated code for the knowledge base.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet>
<Result>
<ROUNDS>3</ROUNDS>
<USERNAME>testuser</USERNA ME>
<BIRDIES>2</BIRDIES>
<PARS>13</PARS>
<BOGIES>28</BOGIES>
<DOUBLES>11</DOUBLES>
<GH>10</GH>
<FH>10</FH>
<PUTTS>108</PUTTS>
<SCORES>264</SCORES>
</Result>
</ResultSet>
Servlet Code:
Error was due to not writing it to the response.
RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
//create the XML from recordset
Document jDOMDoc = rsxml.build();
results.close();
XMLOutputter outputter = new XMLOutputter() ;
StringWriter writer = new StringWriter() ;
outputter.output( jDOMDoc, writer );
writer.close() ;
//respond with output stream
rep.setContentType("text/x ml");
rep.getWriter().println(wr iter.toStr ing());
YUI Javascript:
The error was with resultNode
var myColumnHeaders = [
{key:"ROUNDS",text:"ROUNDS "},
{key:"USERNAME",text:"USER NAME"},
{key:"BIRDIES",text:"BIRDI ES"},
{key:"PARS",text:"PARS"},
{key:"BOGIES",text:"BOGIES "},
{key:"DOUBLES",text:"DOUBL ES"},
{key:"GH",text:"GH"},
{key:"FH",text:"FH"},
{key:"PUTTS",text:"PUTTS"} ,
{key:"SCORES",text:"SCORES "},
];
var myColumnSet = new YAHOO.widget.ColumnSet(myC olumnHeade rs);
// Show over 1000 records
var myDataSource = new YAHOO.util.DataSource("/go lferswired /LeagueSta ndings");
// Show 5000 records -- FireBug must be disabled!
//var myDataSource = new YAHOO.util.DataSource("./p hp/data500 0_proxy.ph p");
// Set the responseType as XML
myDataSource.responseType = YAHOO.util.DataSource.TYPE _XML;
// Define the data schema
myDataSource.responseSchem a = {
resultNode: "Result", // Node name of each result item
fields: ["ROUNDS","USERNAME","BIRD IES","PARS ","BOGIES" ,"DOUBLES" ,"GH","FH" ,"PUTTS"," SCORES"] // Field names
};
var initialRequest = "get=all&output=xml";
var oConfigs = {
caption:"Example: Paginated Over XHR",
initialRequest:initialRequ est,
pageCurrent: 1,
rowsPerPage: 100,
startRecordIndex: 1,
pageLinksLength: 10,
rowsPerPageDropdown: [25,50,100,500]
};
var myDataTable = new YAHOO.widget.DataTable("pa ginated", myColumnSet, myDataSource, oConfigs);
XML:
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet>
<Result>
<ROUNDS>3</ROUNDS>
<USERNAME>testuser</USERNA
<BIRDIES>2</BIRDIES>
<PARS>13</PARS>
<BOGIES>28</BOGIES>
<DOUBLES>11</DOUBLES>
<GH>10</GH>
<FH>10</FH>
<PUTTS>108</PUTTS>
<SCORES>264</SCORES>
</Result>
</ResultSet>
Servlet Code:
Error was due to not writing it to the response.
RStoXML rsxml = new RStoXML(results, "ResultSet", "Result");
//create the XML from recordset
Document jDOMDoc = rsxml.build();
results.close();
XMLOutputter outputter = new XMLOutputter() ;
StringWriter writer = new StringWriter() ;
outputter.output( jDOMDoc, writer );
writer.close() ;
//respond with output stream
rep.setContentType("text/x
rep.getWriter().println(wr
YUI Javascript:
The error was with resultNode
var myColumnHeaders = [
{key:"ROUNDS",text:"ROUNDS
{key:"USERNAME",text:"USER
{key:"BIRDIES",text:"BIRDI
{key:"PARS",text:"PARS"},
{key:"BOGIES",text:"BOGIES
{key:"DOUBLES",text:"DOUBL
{key:"GH",text:"GH"},
{key:"FH",text:"FH"},
{key:"PUTTS",text:"PUTTS"}
{key:"SCORES",text:"SCORES
];
var myColumnSet = new YAHOO.widget.ColumnSet(myC
// Show over 1000 records
var myDataSource = new YAHOO.util.DataSource("/go
// Show 5000 records -- FireBug must be disabled!
//var myDataSource = new YAHOO.util.DataSource("./p
// Set the responseType as XML
myDataSource.responseType = YAHOO.util.DataSource.TYPE
// Define the data schema
myDataSource.responseSchem
resultNode: "Result", // Node name of each result item
fields: ["ROUNDS","USERNAME","BIRD
};
var initialRequest = "get=all&output=xml";
var oConfigs = {
caption:"Example: Paginated Over XHR",
initialRequest:initialRequ
pageCurrent: 1,
rowsPerPage: 100,
startRecordIndex: 1,
pageLinksLength: 10,
rowsPerPageDropdown: [25,50,100,500]
};
var myDataTable = new YAHOO.widget.DataTable("pa
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.