Solved

YUI DataTable with Data Source as a Java Servlet generating XML

Posted on 2007-03-19
8
3,656 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:mayankeagle
ID: 18756867
Can you post the XML?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now