I am curious. how many of you find the need to create complex FTL templates? Specifically, do you find the need to use advance features of the FTL language? Or do you simply grab the data in XML or JSON format and then do whatever you need? Or do you do simple FTL and perform more complex routines in JavaScript?? I would simply like to know what best practice is and what your needs have been in the real world.
I would think that most of you would iterate over the result set (example: <#list> loop ) using FTL language and render the results as needed e.g. JSON , XML etc So are you constantly creating new JSON or XML datasets?
Personally I prefer the pattern where we do all the "heavy" lifting in Java (or occasionaly Java Script) and then only use freemarker for the presentation of the data.
It depends what "complex routines" you're talking about. Freemarker is heavily optimised for string manipulation, so it that's what you need you might be better off doing that in the template. However, mathematical operations, lots of nested IFs, etc. are better off in Java or JavaScript where they can be compiled.
Take a look through the webscripts for Share (in the Share war and in the slingshot namespace on the Repo) for examples.
Although i think that Alfrescos webscripting framework is rather elegant, there are some cases where i prefer to bypass that DeclarativeWebScript/Freemarker combo:
When my primary and only output target is some complex JSON, i prefer to directly create JSON objects (using AbstractWebScript instead of DeclarativeWebScript). Otherwise, i had to double create the build-up of my data both in the webscript and in some Freemarker template
Similar if output target is some complex XML: It is just too easy to create bad XML using a template. It is much safer to construct your XML using say dom4j or some other XML library. (so you can be sure your XML is syntactically valid; you may even validate it against some XML schema if you like