Solved

YUI DataTable with Data Source as a Java Servlet generating XML

Posted on 2007-03-19
8
3,666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

696 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