cancel
Showing results for 
Search instead for 
Did you mean: 

Returning an ArrayList back to Freemarker

bengrah
Champ on-the-rise
Champ on-the-rise
Hi guys,

I've wrote a Java-backed webscript that's returning an ArrayList<String> collection which I can easily print on screen in the freemarker template

<#list list as children>
${children}
</#list>

What I want to do is return an ArrayList of NodeRefs, so that way I can reference properties of nodes on the Freemarker side. So here's my code



unlockedFilesArray.add(row.getNodeRef());
model.put("unlockedNodes", unlockedFilesArray);
return model;



Then in the Freemarker template:

<#list unlockedNodes as children>
${children.properties["cm:name"]}
</#list>

But this throws an error:


freemarker.template.TemplateException: Expected hash. child evaluated instead to freemarker.template.SimpleScalar on line 10, column 55 in org/example/javadir.get.html.ftl.


I'm sure the problem lies with the reference to the ArrayList or the syntax I'm using. Any ideas?

Thanks,
Ben.
1 REPLY 1

afaust
Legendary Innovator
Legendary Innovator
Hello,

the error does not appear to relate to the Freemarker Snippet you've provided. Somehwere in your template you are accessing a variable "child" where the object referenced by that variable is not a hash (object / map). If you can provide more of your template, we might be able to point it out to you - otherwise, the error already states the line and column of the incorrectly access variable.

Regards
Axel