AnsweredAssumed Answered

Freemarker in Web Script can't list objects

Question asked by sgartner on Mar 24, 2010
Latest reply on Mar 25, 2010 by sgartner
I have found the strangest problem.  I have created an object in JavaScript and expected to be able to access it using Freemarker.  I can access objects created in and by freemarker, and I can access arrays created in either JavaScript or Freemarker.  I am hoping someone can tell me what I am doing wrong here.

  <format default="html">any</format>


// test hash
model.hFromJS = {"1":"mouse", "2":"test"};

// test array
model.aFromJS = ["some", "strings"];


Test object in FTL:<br>
<#assign h = {"1":"harbor", "2":"lancaster", "sweet":"cinnamon"} >
<#if h?is_hash   >h is a hash<br>          </#if>
<#if h?is_hash_ex>h is an extended hash<br></#if>
<#assign keys = h?keys>
Length of h?keys = ${keys?size}<br>
<#list keys as key>${key} = ${h[key]}<br> </#list>
Test object from JS:<br>
<#if hFromJS?is_hash   >hFromJS is a hash<br>          </#if>
<#if hFromJS?is_hash_ex>hFromJS is an extended hash<br></#if>
<#assign keys = hFromJS?keys>
Length of hFromJS?keys = ${keys?size}<br>
<#list keys as key>${key} = ${h[key]}<br> </#list>
Test array from JS:<br>
<#– For good measure –>
<#if aFromJS?is_hash    >aFromJS is a hash<br>          </#if>
<#if aFromJS?is_hash_ex >aFromJS is an extended hash<br></#if>
<#if !aFromJS?is_hash   >aFromJS is NOT a hash<br>          </#if>
<#if !aFromJS?is_hash_ex>aFromJS is NOT an extended hash<br></#if>
Length of aFromJS = ${aFromJS?size}<br>
<#list aFromJS as item>${item}<br> </#list>

Output HTML:
Test object in FTL:<br>
h is a hash<br>         
h is an extended hash<br>
Length of h?keys = 3<br>
1 = harbor<br> 2 = lancaster<br> sweet = cinnamon<br>
Test object from JS:<br>
hFromJS is a hash<br>         
hFromJS is an extended hash<br>
Length of hFromJS?keys = 0<br>
Test array from JS:<br>
aFromJS is NOT a hash<br>         
aFromJS is NOT an extended hash<br>
Length of aFromJS = 2<br>
some<br> strings<br>

I'm running Alfresco Community Edition 3.2 which apparently uses FreeMarker 2.3.13.