?
Solved

YUI Datatable and Struts2. Not getting the XML Data from the Action Class

Posted on 2007-10-12
5
Medium Priority
?
2,424 Views
Last Modified: 2010-05-18
Hi

I am using Yahoo User Interface for javascript in my project. I am using the Datatable of YUI. There i am trying to get the Data from XML by refering to the ACtion class. But i am not able to get the data to the datatable. I am attaching the code that i have used.


JAVASCRIPT::
function onClickLoad()
{      

var callback={

success:function(o){
var xmlDoc = o.responseXML;  
var myColumnDefs = [
{key:"Company", label:"Code"},
{key:"Title", label:"Code"},
{key:"Name", label:"Code"},
{key:"Phone", label:"Code"},
{key:"Email", label:"Code"}
];  
var root = o.responseXML.documentElement;

alert("responseXML--"+o.responseXML.documentElement);
/*
var oTitle = root.getElementsByTagName('description')[0].firstChild.nodeValue;
var oDateTime = root.getElementsByTagName('lastBuildDate')[0].firstChild.nodeValue;
var descriptionNode = root.getElementsByTagName('description')[1].firstChild.nodeValue;

*/

var myDataSource = new YAHOO.util.DataSource(xmlDoc);                  
myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;  
myDataSource.connMethodPost = true;  

// Define the data schema
myDataSource.responseSchema = {
resultNode:"Item",
fields:["Company","Title","Name","Email","Phone"]
};

var myDataTable = new YAHOO.widget.DataTable("cellblock1",myColumnDefs,myDataSource,
{caption:" ",selectionMode:"cellblock"});
myDataTable.subscribe("cellMouseoverEvent", myDataTable.onEventHighlightCell);
myDataTable.subscribe("cellMouseoutEvent", myDataTable.onEventUnhighlightCell);
myDataTable.subscribe("cellClickEvent", myDataTable.onEventSelectCell);
myDataTable.subscribe("cellClickEvent",function(e){

var ar=myDataTable.getSelectedTdEls();
var i=0;

for(i=0;i<ar.length;i++)
{
if(document.all){
addRow(ar[i].innerText);
} else{
addRow(ar[i].textContent);
}
}
});
},
failure:function(o){

alet("Failure")

}      
}
var sUrl = '../bills/getICDCPT.action?name=Pradeep';
var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback);
}


ACTION CLASS (.java)

public class DisplayGetCodesAction extends ActionSupport implements ServletRequestAware,ServletResponseAware{
        
private HttpServletRequest request;
private HttpServletResponse response;  
private String name;
public static final long serialVersionUID=876786786786L;
public String execute() throws Exception{
System.out.println("HI IN CPT ICD SERACH");
StringBuffer sb=new StringBuffer();
sb.append("<Item>");      
 sb.append("<Company>BA</Company>");
 sb.append("<Title>SE</Title>");
              sb.append("<Name>XYZ</Name>");
              sb.append("<Email>Xyz@gmail.com</Email>");
              sb.append("<Phone>87778789</Phone>");
              sb.append("</Item>");
              
              
              
              response.setContentType("text/xml");
              response.setHeader("Cache-Control", "no-cache");      
              response.getWriter().write(sb.toString());
              
              System.out.println("REQUEST Get::"+this.getName());
              System.out.println("SB::"+sb.toString());
              System.out.println("Response::"+response.getContentType());
          
                //response.setStatus(HttpServletResponse.SC_NO_CONTENT);
          
                  return SUCCESS;
       }

        public void setServletRequest(HttpServletRequest request){
          this.request = request;
        }

        public HttpServletRequest getServletRequest(){
          return request;
        }

        public void setServletResponse(HttpServletResponse response){
          this.response = response;
        }

        public HttpServletResponse getServletResponse(){
          return response;
        }

      public String getName() {
            return name;
      }

      public void setName(String name) {
            this.name = name;
      }

}



Tell me where i am going wrong.
0
Comment
Question by:pradeep_brat
  • 2
4 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 20063947
Does

              System.out.println("REQUEST Get::"+this.getName());

get printed out?
0
 

Author Comment

by:pradeep_brat
ID: 20064013
Ya that gets printed. But my issue is related to geeting the data within  the XML tags to the YUI Datatatable. I do not think we have anythink much to do with the SOP Statement..


Thanks !!
0
 

Author Comment

by:pradeep_brat
ID: 20221556
Hi i got the solution i have used the Text Type from databae and its working fine..


function onClickLoad()
{
var myColumnDefs = [
{key:"Company", label:"Code"},
{key:"Title", label:"Code"},
{key:"Name", label:"Code"},
{key:"Phone", label:"Code"},
{key:"Email", label:"Code"}
];

/*this is wat i changed  I made TYPE_XML to TYPE_TEXT*/
var myDataSource = new YAHOO.util.DataSource("../bills/getCode.action?name=Pradeep");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_TEXT;

myDataSource.responseSchema = {
 recordDelim: "\n", // Record delimiter
 fieldDelim: ",", // Field delimiter
fields: ["Company","Title","Name","Phone","Email"] // Field names};            
                  
myDataTable = new YAHOO.widget.DataTable("cellblock1",
myColumnDefs,
myDataSource,{caption:" ",selectionMode:"cellblock"});
myDataTable.subscribe("cellMouseoverEvent", myDataTable.onEventHighlightCell);
myDataTable.subscribe("cellMouseoutEvent", myDataTable.onEventUnhighlightCell);
myDataTable.subscribe("cellClickEvent", myDataTable.onEventSelectCell);
myDataTable.subscribe("cellClickEvent",function(e){

var ar=myDataTable.getSelectedTdEls();
var i=0;
for(i=0;i<ar.length;i++)
{
      if(document.all){
       addRow(ar[i].innerText);
} else{
      addRow(ar[i].textContent);
}
}
});            
}

And in Servlet (.java class)
 response.getWriter().write("Company,Title,Name,Phone,Email\n" +
              "Company,Title,Name,Phone,Email\n"+
              "Company,Title,Name,Phone,Email\n"+
              "Company,Title,Name,Phone,Email\n"+
              "Company,Title,Name,Phone,Email\n"+
              "Company,Title,Name,Phone,Email\n");
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20432394
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month17 days, 3 hours left to enroll

862 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