No top level scope?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2013 06:54 PM
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.
The freemarker which takes the model from the Java is erroring:
Any suggestions on why there isn't a top level scope / how I can get one? Thanks.
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.
Labels:
- Labels:
-
Archive
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2013 05:01 AM
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?
could you post your ftl?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2015 08:28 AM
If anyone still wants to know how to properly instantiate ScriptNode from a pure java-backed webscript, here's how:
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
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
