Categories | Question details Back To List | ||
XML return (java - struts) to GridObject... Hello friend, is possible dhtmlXGridObject catch a XML return through Action Struts (like a response.getWriter() - Java)? example: my page (jsp): ... <script> var mygrid; function doInitGrid(){ mygrid = new dhtmlXGridObject('mygrid_container'); mygrid.setImagePath("<%=request.getContextPath()%>/scripts/imgs/"); mygrid.setHeader("Test1,Test2,Test3,Test4"); mygrid.setInitWidths("*,100,100,100"); mygrid.setColAlign("left,center,center,center") mygrid.setSkin("light"); mygrid.setColTypes("ro,price,price,price"); mygrid.init(); mygrid.clearAll(); mygrid.loadXML("/webcalculator/calculator.do?action=buildXMLGrid"); } </script> ... My action Struts: ... import org.jdom.Document; import org.jdom.Element; import org.jdom.output.XMLOutputter; ... // Important: I´m using Jdom to generate XML public ActionForward buildXMLGrid(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try{ List nodes = new ArrayList(); // Important: I´m using Jdom to generate XML Element rows = new Element("rows"); Element row = new Element("row"); Element cell = new Element("cell"); for (Integer a = 0 ; a <=3 ; a++){ nodes.add(new Element("cell").setText(a.toString())); } cell.setChildren(nodes); row.addContent(cell); rows.addContent(row); Document doc = new Document(); doc.setRootElement(rows); //Imptrimindo o XML XMLOutputter xout = new XMLOutputter(" ", true); xout.setEncoding("iso-8859-1"); xout.output(doc, System.out); response.setContentType("text/xml; charset=iso-8859-1"); response.setHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate"); response.addHeader("Cache-Control", "post-check=0, pre-check=0"); response.setHeader("Pragma", "no-cache"); PrintWriter out = response.getWriter(); out.print(xout); out.close(); return null; } catch (Exception e){ return null; } ... Answer posted by Support on Jul 28, 2008 02:48 >> is possible dhtmlXGridObject catch a XML return through Action Struts (like a response.getWriter() - Java)? Yes, it possible , while response contains valid XML data and sent with valid headers - it is not difference is data as static XML file or generated by any kind of server side script. As far as I can see provided code is correct. If , by any chance, you still get "Incorrect XML" message - please check http://dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Common_Problems_in_Grid.html#grid_art_comprob |