AnsweredAssumed Answered

Pass result from javascipt to ftl template

Question asked by robertoroberto on Jan 30, 2008
Latest reply on Jan 30, 2008 by mark.smithson
Hi, I have a webscript that add categories to the classification tree:

———– addCategoryPathtoPath.js ———

function addCategoryPath2Path(newpath,pth)
{
    
  var nodes_x_level = decodeURI(pth).split(".");
  var node = null;


var rootTgt = null, nodeIndex = null;
var rootNodes = classification.getRootCategories("cm:generalclassifiable");
var found = false; var styleFound="";

for(node in nodes_x_level)
{  found = false;
for(nodeIndex in rootNodes)

    rootTgt = null;   
if (rootNodes[nodeIndex].properties.name==nodes_x_level[node])
       { rootTgt = rootNodes[nodeIndex];
         out+="matching…"+rootTgt.properties.name+" == "+nodes_x_level[node]+"<br>";
        break; }
  }
   if  (rootTgt!=null)
  {   rootNodes = rootTgt.immediateSubCategories;  
      found=true;
   } else { out+="No matching for node:"+nodes_x_level[node]+" (abort) <br> <br>"; break; }


}



   if  (found==true) 
{
var idx = 0;
var  tmpCatNode = null;
var addedcategories = decodeURI(newpath).split(".");

for (idx in addedcategories)
{   tmpCatNode = rootTgt.createSubCategory(addedcategories[idx]);   
    rootTgt =tmpCatNode;
}

  styleFound ="<font color=green>Sub-Categories Path : <br> <em>"+newpath+"</em>  was created! </font>"; 

}
  else 
{  styleFound="<font color=red>Creation Failed!</font>";  }

   return (out+styleFound);
}


function doIt(){
   var name = args["subpath"]; var path = args["path"];
   res =  addCategoryPath2Path(name,path);
   return res;
}

model.res=doIt();


—— addCategoryPathtoPath.get.html.ftl ————

<html>
   <head>
   </head>
   <body>
      ${res}
      
   </body>
</html>

I have this error; Can you help me? How can I pass result(res) from javascript to ftl response file?

500 Description: An error inside the HTTP server which prevented it from fulfilling the request. 
  
Message: Error during processing of the template 'Expression res is undefined on line 6, column 19 in org/alfresco/office/addCategoryPathtoPath.get.html.ftl.'. Please contact your system administrator. 
  
Exception: freemarker.core.InvalidReferenceException - Expression res is undefined on line 6, column 19 in org/alfresco/office/addCategoryPathtoPath.get.html.ftl. 


regards

Outcomes