cancel
Showing results for 
Search instead for 
Did you mean: 

No top level scope?

cs02rm0
Champ in-the-making
Champ in-the-making
Hi

I'm reworking a Javascript webscript into a Java one. The Java one now extends DeclarativeWebscript and returns a Map of Lists of Maps, etc. down to a ScriptNode.

item.put("node", new ScriptNode(nodeRef, _serviceRegistry));


The freemarker which takes the model from the Java is erroring:


Caused by: freemarker.template.TemplateModelException: get(properties) failed on instance of org.alfresco.repo.jscript.ScriptNode

Caused by: java.lang.reflect.InvocationTargetException

Caused by: java.lang.NullPointerException
   at org.mozilla.javascript.ScriptableObject.getTopLevelScope(ScriptableObject.java:1483)
   at org.mozilla.javascript.ScriptRuntime.setObjectProtoAndParent(ScriptRuntime.java:3106)
   at org.mozilla.javascript.Context.newArray(Context.java:1547)
   at org.alfresco.repo.jscript.ValueConverter.convertValueForScript(ValueConverter.java:121)
   at org.alfresco.repo.jscript.ScriptNode$NodeValueConverter.convertValueForScript(ScriptNode.java:3258)
   at org.alfresco.repo.jscript.ScriptNode$NodeValueConverter.convertValueForScript(ScriptNode.java:3237)
   at org.alfresco.repo.jscript.ScriptNode.getProperties(ScriptNode.java:835)
   … 116 more


Any suggestions on why there isn't a top level scope / how I can get one? Thanks.
2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
did you mean you have changed your webscript form javascript based to java backed webscript and now you are facing problem in the ftl?
could you post your ftl?

electroshokker
Champ on-the-rise
Champ on-the-rise
If anyone still wants to know how to properly instantiate ScriptNode from a pure java-backed webscript, here's how:


Context context = Context.enter();
Scriptable scope = context.initStandardObjects();
try
{
     scriptNode = new ScriptNode(nodeRef, services, scope);
}
finally
{
     Context.exit();
}


For more explanation, see https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scopes_and_Contexts

Basically, while the alfresco code supports creating ScripNode instances without a context and scope, many of the ScriptNode methods actually require a context and scope, or they will throw NullpointerExceptions.

This is still true in Alfresco 5