Solved

YUI DataTable with Data Source as a Java Servlet generating XML

Posted on 2007-03-19
8
3,662 Views
Last Modified: 2008-01-09
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(jDOMDoc); 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/xml");
            rep.getOutputStream();

Javscript:

var myColumnHeaders = [
    {key:"ROUNDS",text:"ROUNDS"},
    {key:"USERNAME",text:"USER"},
    {key:"BIRDIES",text:"BIRDIES"},
    {key:"PARS",text:"PARS"},
    {key:"BOGIES",text:"BOGIES"},
    {key:"DOUBLES",text:"DOUBLES"},
    {key:"GH",text:"GH"},
    {key:"FH",text:"FH"},
    {key:"PUTTS",text:"PUTTS"},
    {key:"SCORES",text:"SCORES"},
];
var myColumnSet = new YAHOO.widget.ColumnSet(myColumnHeaders);

// 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.responseSchema = {
    resultNode: "ResultSet.Result", // Node name of each result item
    fields: ["ROUNDS","USER","BIRDIES","PARS","BOGIES","DOUBLES","GH","FH","PUTTS","SCORES"] // Field names
};
//Pagination
var initialRequest = "get=all&output=xml";
var oConfigs = {
        caption:"Example: Paginated Over XHR",
        initialRequest:initialRequest,

        pageCurrent: 1,
        rowsPerPage: 100,
        startRecordIndex: 1,
        pageLinksLength: 10,
        rowsPerPageDropdown: [25,50,100,500]
};
var myDataTable = new YAHOO.widget.DataTable("paginated", myColumnSet, myDataSource, oConfigs);

0
Comment
Question by:fortneci
8 Comments
 
LVL 15

Expert Comment

by:stanscott2
ID: 18752088
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"
0
 

Author Comment

by:fortneci
ID: 18752452
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?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18756867
Can you post the XML?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:fortneci
ID: 18769224
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet>
    <Result>
         <ROUNDS>3</ROUNDS>
         <USERNAME>testuser</USERNAME>
         <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>
0
 

Author Comment

by:fortneci
ID: 18782809
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:
0
 

Author Comment

by:fortneci
ID: 18783699
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</USERNAME>
         <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/xml");
            rep.getWriter().println(writer.toString());


YUI Javascript:
The error was with resultNode

var myColumnHeaders = [
    {key:"ROUNDS",text:"ROUNDS"},
    {key:"USERNAME",text:"USERNAME"},
    {key:"BIRDIES",text:"BIRDIES"},
    {key:"PARS",text:"PARS"},
    {key:"BOGIES",text:"BOGIES"},
    {key:"DOUBLES",text:"DOUBLES"},
    {key:"GH",text:"GH"},
    {key:"FH",text:"FH"},
    {key:"PUTTS",text:"PUTTS"},
    {key:"SCORES",text:"SCORES"},
];
var myColumnSet = new YAHOO.widget.ColumnSet(myColumnHeaders);

// Show over 1000 records
var myDataSource = new YAHOO.util.DataSource("/golferswired/LeagueStandings");
// Show 5000 records -- FireBug must be disabled!
//var myDataSource = new YAHOO.util.DataSource("./php/data5000_proxy.php");

// Set the responseType as XML
myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;

// Define the data schema
myDataSource.responseSchema = {
    resultNode: "Result", // Node name of each result item
    fields: ["ROUNDS","USERNAME","BIRDIES","PARS","BOGIES","DOUBLES","GH","FH","PUTTS","SCORES"] // Field names
};

var initialRequest = "get=all&output=xml";
var oConfigs = {
        caption:"Example: Paginated Over XHR",
        initialRequest:initialRequest,

        pageCurrent: 1,
        rowsPerPage: 100,
        startRecordIndex: 1,
        pageLinksLength: 10,
        rowsPerPageDropdown: [25,50,100,500]
};
var myDataTable = new YAHOO.widget.DataTable("paginated", myColumnSet, myDataSource, oConfigs);
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 19538615
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question