AnsweredAssumed Answered

Inconsistencies in using date property in freemarker

Question asked by zladuric on Oct 9, 2012
Latest reply on Oct 9, 2012 by zladuric

I'm added a custom aspect to site on creation, and it holds a property of type date:

Now, I'm extending the site.lib.ftl file to display this date:
"startdate": "<#if site.node.hasAspect("my:customAspect")>${["my:customAspectDate"]?string("yyyy-MM-dd")}</#if>",

Since I could not get to a site.node in the macro itself, I've extended the macro parameter list:
<#macro siteJSONManagers site siteNode roles>
so I can call it from site.get.json.ftl as well as person.sites.get.json.ftl:
<@siteLib.siteJSON site=site siteNode=siteNode />

Now, for site.get.js I prepare the sitenode in javascript:
model.siteNode = site.node; // or the same with site.getNode;

My date is parsed correctly.
However, when calling the macro from person.sites.get.json.ftl, I cannot prepare the site.node in javascript controller, so I do it instead in freemarker (by calling it directly):
<@siteLib.siteJSONManagers site=site siteNode=site.node roles=roles/>

In using this form, I get this exception:
"09090011 Wrapped Exception (with status template): 09090096 Error during processing of the template 'Expected method.[\"my:customAspectDate\"]?string evaluated instead to freemarker.template.SimpleScalar on line 59, column 71 in org\/alfresco\/repository\/site\/site.lib.ftl.'. Please contact your system administrator."
If I just display this scallar (${["my:customAspectDate"]}), I get org.mozilla.javascript.NativeDate as a string in my resulting JSON:
"startdate": "org.mozilla.javascript.NativeDate@7a6e5e2e",

I can repeat that by setting the same parameter for siteNode in the site.get.json.ftl.
I can even repeat it if I use["cm:created"].

It seems to me that when javascript controller creates a model object from a node, the created date props get created as java.util.Date, or whatever Freemarker uses, and that when Freemarker itself creates that property, it will be turned into org.mozilla.javascript.NativeDate.

Can somebody please point out how can I could improve my work? What can I use so that my calls get the same values?

I am using Alfresco from SVN HEAD if it makes any difference.