• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2428
  • Last Modified:

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

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
pradeep_brat
Asked:
pradeep_brat
  • 2
1 Solution
 
TimYatesCommented:
Does

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

get printed out?
0
 
pradeep_bratAuthor Commented:
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
 
pradeep_bratAuthor Commented:
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
 
Computer101Commented:
PAQed with points refunded (250)

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now