Solved

YUI DataTable with Data Source as a Java Servlet generating XML

Posted on 2007-03-19
8
3,668 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

695 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