cancel
Showing results for 
Search instead for 
Did you mean: 

Probulem JavaScript API processTemplate

sugai
Champ in-the-making
Champ in-the-making
Smiley Sad Hi,

I could use the JavaScript API processTemplate on the Alfresco-community-tomcat-1.4.0 and 2.0.0.
Now, I have installed the Alfresco-community-tomcat-2.1.0.
The following script can not execute on Alfresco, only 2.1.0.

Input form

<html>
<head>
<title>***** ex_listDocsSpace.html *****</title>
</head>
<body>
<form method="POST" action="http://vaio-sugai:8080/alfresco/command/script/execute" accept-charset="UTF-8" >
<br>JavaScript call from HTML form<br>
<br>
<input type="text" name="scriptPath" size="100" value="/Company Home/User Homes/ex_listDocsSpace.js">
<br><br>
<input type="text" name="spacePath" size="100" value="User Homes">
<br><br>
<input type="text" name="templatePath" size="100" value="User Homes/ex_listDocsSpace.ftl">
<br><br>
<input type="submit">
</form>
</body>
</html>

[JavaScript code]

var arg = new Array();
arg = args;
var script = arg["scriptPath"];
var spacePath = arg["spacePath"];
var templatePath = arg["templatePath"];

var result = "args check !" + "<br>";
result +=  "arg[script] : "  + script + "<br>";
result +=  "arg[spacePath] : "  + spacePath + "<br>";
result +=  "arg[templatePath] : "  + templatePath + "<br><br>";   // 10

space = userhome;
var spaceNode = space.childByNamePath(spacePath);
if ( spaceNode == null) {
     result +=  "spaceNode not found !" + "<br>";
} else {
     result += "spaceNode.name = " + spaceNode.name + "<br>";
}

// Get templateNode
var templateNode = space.childByNamePath(templatePath);
result += "templateNodeName = " + templateNode.name + "<br>";

// set spaceNode to current space
space = spaceNode;
// Execute processTemplate
var outString = new String("");
outString +=  space.processTemplate(templateNode);
result += outString + "<br>";                  
result;

[Template]

<#– Renders list of all the documents in the Space –>
<table>
<#list space.children as child>
    <#if child.isDocument>
       <tr><td>${child.properties.name}</td></tr>
    </#if>
</#list>
</table>
    system error messages

    org.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/90f0221e-5142-11dc-a12e-7f4bdf46ace9': Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.error.AlfrescoRuntimeException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.mozilla.javascript.WrappedException: Wrapped org.alfresco.service.cmr.repository.TemplateException (AlfrescoScript#28 )
    caused by:
    org.alfresco.service.cmr.repository.TemplateException
    caused by:
    java.lang.NullPointerException
My PC is running Windows XP Home Edition Version 2002 Service Pack 2.
Are there any changes ?
Please advice me.
13 REPLIES 13

sugai
Champ in-the-making
Champ in-the-making
Suleyman

I am studying SDK, too.

I wait for the next  release of Niightly build.

I hope that it is released in approximately 10 days.

regards

kevinr
Star Contributor
Star Contributor
The merge has happened today:
http://issues.alfresco.com/browse/CHK-1289

It should be in tonights nightly build.

Kevin

fogo
Champ in-the-making
Champ in-the-making
Is there a work around for this?

kevinr
Star Contributor
Star Contributor
There is no workaround as it requires a code change. I have made the fixed .class file available here.

You will need to stop the server, then replace the class file org\alfresco\repo\processor\TemplateServiceImpl.class in the repository.jar file inside the alfresco.war file - then repack the jar into the war and restart the server.

Hope this helps,

Kevin