cancel
Showing results for 
Search instead for 
Did you mean: 

Inconsistencies in using date property in freemarker

zladuric
Champ on-the-rise
Champ on-the-rise
Hello,

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

Now, I'm extending the site.lib.ftl file to display this date:
"startdate": "<#if site.node.hasAspect("my:customAspect")>${siteNode.properties["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. siteNode.properties[\"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 (${siteNode.properties["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 siteNode.properties["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.
1 REPLY 1

zladuric
Champ on-the-rise
Champ on-the-rise
Aaaaaand to answer my own question, in case somebody else bumps into this wall for two days too:

<#assign nodeR=companyhome.childByNamePath["Sites/" + site.shortName] />
"startdate": "<#if nodeR.hasAspect("my:customAspect")>${nodeR.properties["my:customAspectDate"]?string("yyyy-MM-dd")}</#if>",

I don't know why it works this way and not the other, though.