Archive for the 'AJAX' Category

How to solve XML reffers to not existing parent error of dhtmlxTree

Written by coregps on Thursday, March 13th, 2008 in Java, AJAX, XML.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

When I use dhtmlxTree dynamical loading with jsp, I always get the following exception:

Error type: DataStructure
Description: XML reffers to not existing parent

The code of the jsp page is as following:

<html>
<head>
</head>
<body>
    <link rel="STYLESHEET" type="text/css" href="css/dhtmlxtree.css">
    <script  src="js/dhtmlxcommon.js"></script>
    <script  src="js/dhtmlxtree.js"></script>
    <div id="treeboxbox_tree" style="width:100%; height:218;background-color:#f5f5f5;border :1px solid Silver;; overflow:auto;"></div>
    <script type="text/javascript">
		tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
		tree.attachEvent("onClick",onNodeSelect);
		tree.setImagePath("images/tree/");
		tree.setXMLAutoLoading("AdminFolderServlet?action=folder_treeview");
		tree.loadXML("AdminFolderServlet?action=folder_treeview&id=1");
		function onNodeSelect(nodeId){
		    document.getElementById("parent_folder_id").value = nodeId;
		}
    </script>
</body>
</html>

And the following is the code snippet used to generate XML file of the tree:

String id = request.getParameter("id");
if (id == null) id = "1";
Vector folders = Folder.getFolders(Integer.parseInt(id));
StringBuffer buff = new StringBuffer("< ?xml version=\"1.0\"?>“);
buff.append(”
“);
for (int i = 0; i < folders.size(); i++) {
	Folder f = (Folder)folders.get(i);
	buff.append("“);
}
buff.append(”“);
response.setContentType(”text/xml”);
response.setHeader(”Cache-Control”,”no-cache”); //HTTP 1.1
response.setHeader(”Pragma”,”no-cache”); //HTTP 1.0
response.setDateHeader(”Expires”, 0); //prevents caching at the proxy server
response.getWriter().write(buff.toString());

The generated XML is well formed.

<?xml version="1.0"?>
<tree id='1'>
	<item child='1' id='2' text='Games' im0='folderClosed.gif' im1='folderOpen.gif' im2='folderClosed.gif'></item>
	<item child='1' id='3' text='Music' im0='folderClosed.gif' im1='folderOpen.gif' im2='folderClosed.gif'></item>
	<item child='0' id='4' text='Books' im0='folderClosed.gif' im1='folderOpen.gif' im2='folderClosed.gif'></item>
	<item child='1' id='5' text='Movies' im0='folderClosed.gif' im1='folderOpen.gif' im2='folderClosed.gif'></item>
	<item child='1' id='6' text='Photos' im0='folderClosed.gif' im1='folderOpen.gif' im2='folderClosed.gif'></item>
	<item child='0' id='14' text='Articles' im0='folderClosed.gif' im1='folderOpen.gif' im2='folderClosed.gif'></item>
</tree>

I finally found the solution. The id attribute of the tree element must point to the parent id, which data will be linked, by default super-root ID = 0, but it can be changed while tree initialization ( 4th parameter of constructor ), In case of dynamic loading the tree id must be equal to the parent ID for which data requested.

In my database, the root id of the top level folder is 1, however, I use 0 in the tree initialization method.

tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);

So, I got the exception. After changing the fourth parameter to 1, it works well.

tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",1);

Hope this can help someone else in the future :)

propecia pricebuy propeciaorder ventolinbuy ventolincheap xenicalxenical onlneorder revatiorevatiofemale viagra onlinefemale viagracompare viagra cialisorder viagra cialischeap vpxlvpxl onlineorder levitra professionallevitra professional onlinebuy levitra prescriptionlevitralevitra onlineorder cialis jellycialis jellyorder cialis soft tabsbuy cialis soft tabsorder cialis super activecheap cialis super activeorder generic cialischeap generic cialiscialis professionalcialis professional onlinepurchase cialiscialis pricecialischeap brand viagrabrand viagra onlineviagra jelly onlineviagra jelly priceorder viagra soft tabsbuy viagra soft tabsviagra super active onlineviagra super activeorder generic viagracheap generic viagraviagra professional onlineviagra professionalpurchase viagraviagracheap viagraorder vpxlbuy vpxltake viagra cialis togetherorder viagra cialis onlinelevitra professional pricecheap levitra professionallevitrabuy levitracialis jelly pricecheap cialis jellycialis soft tabscialis soft tabs onlineorder cialis super activecialis super activeorder generic cialischeap generic cialischeap cialis professionalcialis professional priceorder cialischeap cialischeap brand viagrabrand viagra onlineorder viagra jellyviagra jelly pricecheap viagra tabsviagra soft tabs onlineviagra super active onlinecheapviagra super activegeneric viagrageneric viagra onlineorder viagra professionalcheap viagra professionalviagra pricebuy viagrabuy cialis ukwhat is cialiscialis sale ukpurchase generic cialisbuy cialis money orderbuy cialis low costbuy cialis in ukbuy cialis huge discounts onlinebuy cialis from usa onlinebuy cialis fedex shippingorder cialis and viagrabuy cialis no prescriptionbuy cialis amexbuy cialis by mailbest cialis pricesorder viagra international shipscheapest place to buy viagra onlineviagra purchasebuy taladafil viagraviagra mail order ukviagra low pricecheap site buy viagrabuy generic viagra canadaviagra drugs order brand pillviagra best quality lowest priceshow to buy viagra onlinebuy viagra online securelybuy viagra online pharmacybuy viagra online get prescriptionbest way to take levitrabest price viagra or levitrabest price viagra official drug storeorder viagra with master cardorder viagra upsbuy viagra in englandbuy viagra consumers discount

Ajax tutorial

Written by coregps on Friday, April 6th, 2007 in AJAX.

SYS-CON Announces Two New “AJAXWorld University Bootcamp” Dates

Written by coregps on Sunday, November 12th, 2006 in AJAX.

SYS-CON Announces Two New “AJAXWorld University Bootcamp” Dates ? SYS-CON Events has announced that, due to popular demand, more ‘AJAXWorld University Bootcamps’ (http://ajaxbootcamp.sys-con.com) will be taking place on two new dates in 2007. The next two dates are January 22, 2007 and March 19, 2007 - both in New York City, at the historic Roosevelt Hotel in midtown Manhattan.

Web 2.0 vs Web 1.0: Why Ajax is Conceptually Better

Written by coregps on Sunday, November 12th, 2006 in AJAX.

Web 2.0 vs Web 1.0: Why Ajax is Conceptually Better ? We now serve ‘pure data’ or content, without all the formatting clutter that scrambled our data back in Web 1.0. The reduction of redundancy is a nice side effect, not having to download the layout on every refresh.

Create checked radio button dynamically

Written by coregps on Friday, September 22nd, 2006 in AJAX, Web Design.

I meet some trouble when creating radio buttons through javascript. My code is something like this:

function createRadioButton(elt_name, elt_value, elt_label, is_selected) {
    var inputElement = document.createElement('input');
    inputElement.setAttribute('type', 'radio');
    inputElement.setAttribute('name', elt_name);
    inputElement.setAttribute("value", elt_value);
    var func = new Function("alert(this.value + ' is selected!')");
    inputElement.onclick = func;

    if (is_selected) {
        inputElement.setAttribute("checked", "checked");
    }

    var divElement = document.getElementById("container");
    divElement.appendChild(inputElement);
    divElement.appendChild(document.createTextNode(elt_label));
    divElement.appendChild(document.createElement("br"));
}

This works perfectly in Firefox. but in Internet Explorer the radio buttons can’t be selected. After googling the internet, I find a solution which works well in IE:

var inputElement = document.createElement(’<input type=”radio” name=”‘ + elt_name + ‘” />’);

However, another problem arises. IE leaves the radio button unchecked even I set the checked status in my javascirpt like this:

inputElement.setAttribute(”checked”, “checked”);

It seems that this has no side-effect on the behavior of IE before I insert the radio button into the DOM. So I move the code used to set the checked attribute down to after the statement used to insert the radio button into the document, it works fine.

The following is the full source code:

<html>
<head>
<title>create radio button</title>
<script type="text/javascript">
function createRadioButton(elt_name, elt_value, elt_label, is_selected) {
    var inputElement;
    try{
        inputElement = document.createElement('<input type="radio" name="' + elt_name + '" />');
    }catch(err){
        inputElement = document.createElement('input');
        inputElement.setAttribute('type', 'radio');
        inputElement.setAttribute('name', elt_name);
    }
    inputElement.setAttribute("value", elt_value);
    var func = new Function("alert(this.value + ' is selected!')");
    inputElement.onclick = func;

    var divElement = document.getElementById("container");
    divElement.appendChild(inputElement);
    divElement.appendChild(document.createTextNode(elt_label));
    divElement.appendChild(document.createElement("br"));

    if (is_selected) {
        inputElement.setAttribute("checked", "checked");
    }
}
function testFunc() {
   var divElement = document.getElementById("container");

   // empty object of its children
   var len = divElement.childNodes.length;
   for (var i = 0; i < len; i++) {
       divElement.removeChild(divElement.childNodes[0]);
   }

   // alternate method
   /*
   while(divElement.hasChildNodes() == true) {
      divElement.removeChild(divElement.childNodes[0]);
   }
   */

   createRadioButton('sex', 'm', 'male', true);
   createRadioButton('sex', 'f', 'female', false);
}
</script>
</head>
<body>
<h1>Create radio button dynamically</h1>
<div id="container"></div>
<input type="button" value="Create" onclick="testFunc()" />
</body>



Site Navigation