Link to home
Start Free TrialLog in
Avatar of pradeep_brat
pradeep_brat

asked on

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.
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Does

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

get printed out?
Avatar of pradeep_brat
pradeep_brat

ASKER

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 !!
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");
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial